Академический Документы
Профессиональный Документы
Культура Документы
1 About ........................................................................................... 4
Forums: ................................................................................ 50
YouTube: .............................................................................. 50
Blogs: ................................................................................... 51
DevTV: ................................................................................. 51
Training: ............................................................................... 51
Over the last 10 years at Symetri, I have worked with several companies to
assist and mentor with their Design Automation needs. These include Ellis
Furniture who later won the Autodesk Inventor of the Year award in 2012 and
Penny Hydraulics who used iLogic to transform the good lifts division of their
business.
Symetri has more than 400 skilled employees and 100,000 daily users across
Northern Europe, providing our clients with expert guidance covering
everything from 3D modelling and simulation to Product Lifecycle
Management, Building Information Modelling and Facility Management.
Many of our solutions follow the principles of Lean, and the benefits include
lower development and production costs, a reduction in materials used and
shorter time to market, not to mention leaving more room for creativity and
better end results.
Although the diagram shows that the top-level rule is named PROCESS_RULE,
in reality it can have any name. It is recommended that the top level rule is
By using this structure, no rules are set to run automatically as users should
want to retain control of when rules run and would have the option to run all
rules or just ones to update certain sheets.
To store the active sheet before configuring the drawing users can set a
variable detailing the sheet and retrieving it later:
CURRENTSHEET = ActiveSheet
iLogicVb.RunRule("SHEET 1 RULE")
iLogicVb.RunRule("SHEET 2 RULE")
ActiveSheet = CURRENTSHEET
In the examples detailed in this lab, there are some variables in the model
that are required in the drawing. There are many ways to pass this
information which will be used. The first of these examples is to pass
variables using the shared variable snippets. To understand shared variables,
think of them as parameters that are not tied to a model but instead to the
Inventor session; they exist and are stored in memory rather than within the
document. Users can create, edit, delete and check they exist and can allow
a user to make the same information available to multiple rules and
documents. Shared Variables can be found in the standard iLogic snippets
under Variables.
Shared variables are often used where information is retrieved and needs to
be stored for future use in multiple files.
Often a user will want to open and update a drawing from the model. In this
situation it can be a good idea to ensure that the drawing does not
automatically open and configure after every model change but also that
when the drawing is opened the rule only run as needed. Many users will set
event triggers that automatically run drawing rules when the drawing is
opened. Although this works it can lead to issues with Vault workflows, the
job processor and task scheduler depending on what the rules do. Instead
code can be added to models that will open a drawing, run a named drawing
rule, save drawing and close drawing code giving control of when the
document is updated.
FullFilename = ThisDoc.ChangeExtension(".dwg")
Dim oDrawingDoc As DrawingDocument = ThisApplication.Documents.Open(FullFilename)
Alternatively, if the name and location are different then users can use code
such as:
Once the drawing is open, the top-level rule is required to run. This is done
by accessing the iLogic automation interface and stating what the rule name
is. In the example below, it is called C360_OnPublishDrawing:
Drawings can have title blocks reference iproperties of models as well as the
documents own. If using Autodesk Vault it can be a good idea that each
document has its own properties filled in to each searching for data. As a
result, there is a need to keep drawing and model properties in sync (often
except for revision when using vault document workflows as each document is
managed as its own document with its own revision).
Inventor semi fulfils this need to sync properties, out of the box, by allowing
users to set what properties to copy via a drawings document setting. Once
set, a user can click on the ribbon to manually copy the properties from the
model to the drawing at any time. This process can be automated via ilogic
code designed to execute the same function as the ribbon command.
The code can also be adapted to click commands from the ribbon. Users can
output a list of commands that can be used by running the Print list of all
Inventor Commands sample from the API documentation.
5. Change the units options to Width: 500; Height: 500; Depth: 300;
Shelves: 3; no doors
6. Start a new DWG drawing of the model and save it to the same
location as the model using the same name ie, Unit.dwg
8. Create a second sheet and place the left side panel onto it. Again,
create a Front, Top and Side View (please use capitals).
iLogicVb.RunRule("SHEET 1 RULE")
iLogicVb.RunRule("SHEET 2 RULE")
iLogicVb.RunRule("OUTPUTS RULE")
14.Still editing the rule; Expand the standard snippets and find the
drawing snippets. In here double click Active Sheet and add it into as
the top and bottom line of the code. Add CURRENTSHEET = before
the snippet on the first line and add = CURRENT SHEET after the
snippet on the bottom line.
16.Edit each of the sheet rules and add the snippet “Activate a Sheet” to
the code window. Edit the code with the correct sheet name
17.Swap to the model and edit the rule named drawing rule. This rule
should currently be blank.
SharedVariable.Remove("DWF_WANTED")
SharedVariable.Remove("PDF_WANTED")
End If
auto = iLogicVb.Automation
auto.RunRule(oDrawingDoc, "C360_OnPublishDrawing")
21.The rule should look similar to that below at which point swap back to
the drawing.
auto = iLogicVb.Automation
auto.RunRule(oDrawingDoc, "C360_OnPublishDrawing")
oDrawingDoc.Save
oDrawingDoc.Close
SharedVariable.Remove("DWF_WANTED")
SharedVariable.Remove("PDF_WANTED")
End If
22.In the drawing, open the parameters (ribbon > manage >
Parameters). Create 2 true or false parameters named GEN_PDF and
GEN_DWF
23.Edit the Outputs Rule and add in the following code to create PDFs and
DWFs of the drawing:
changedNamepdf = ThisDoc.ChangeExtension(".pdf")
ThisDoc.Document.SaveAs(changedNamepdf , True)
ThisDoc.Launch(changedNamepdf)
changedNamedwf = ThisDoc.ChangeExtension(".dwf")
ThisDoc.Document.SaveAs(changedNamedwf , True)
ThisDoc.Launch(changedNamedwf)
24.Continue editing the outputs rule and add code to search for the
shared variables above the previous code. If found set the value of
each drawing parameter to the relevant shared variable. Once done
set the outputs to only run if the relevant value is true via an if
statement.
26.From the 3d Model, open the form and test the options at the bottom
to update the drawing, output PDFs, Output DWFs
27.Open the drawing document settings found on the tools tab of the
ribbon.
28.Navigate to the drawing tab and find the option “Copy model iproperty
settings”
This code acts the same as a user manually clicking “Update Copied
Properties” on the manage tab of the ribbon.
33.Edit the iLogic event triggers found on the ribbon on the manage tab.
Set the rule “UPDATE COPIED PROPS RULE” to trigger before save and
on a view change.
Typically, in order to determine the scale required for a view several pieces of
information are required: Sheet size & Model size
The sheet height and width can be accessed directly from iLogic snippets to
be used in calculations. These are especially useful when determining the
position of views.
A common mistake user makes when first automating drawings is to use the
rules browser window to drill through the view and add a reference to a
parameter directly. This works while testing a model however it fails after the
model file is renamed. This is similar to why the browser nodes when using
iLogic in a 3D model should be renamed to be static.
E.g. A users wants to reference the UNIT_HEIGHT from a model called UNIT.
Drilling through the rules browser a user could find the parameter and double
click on it to add it to the rules window. This code would be written:
Parameter("UNIT.iam.UNIT_HEIGHT")
The issue with this is that should the drawing and model be copied in vault
then the assembly name will not necessarily be UNIT.IAM. In this scenario a
user should use code to find the model reference then use that to access the
AssyModelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
RetrievedUnitHeight = Parameter(AssyModelName, "UNIT_HEIGHT")
Once retrieved this parameter can be used within If and Case statements to
determine drawing configurations.
2. Either continue with the drawing from the last exercise or open UNIT -
EX2 START.dwg from the exercise 2 folder.
4. Use the snippet named “Model Document Name” (in the iLogic
advanced drawing API snippets) to reference the model.
6. Using the view scale snippet, set the required scale for the views.
Note that only the Base & Iso views need to be scaled as projections
will scale from the parent view.
'Set view scales based on height and width. Depth might also be a factor
in some situations
If UnitModelHeight >= UnitModelWidth Then
Select Case UnitModelHeight
Case 500, 600
ActiveSheet.View("FRONT").Scale = 0.15
ActiveSheet.View("ISO").Scale = 0.15
Case 700, 800
ActiveSheet.View("FRONT").Scale = 0.12
ActiveSheet.View("ISO").Scale = 0.12
Case 900, 1000
ActiveSheet.View("FRONT").Scale = 0.10
ActiveSheet.View("ISO").Scale = 0.05
End Select
Else
Select Case UnitModelWidth
Case 400, 500, 600
ActiveSheet.View("FRONT").Scale = 0.15
ActiveSheet.View("ISO").Scale = 0.15
Case 700, 800
ActiveSheet.View("FRONT").Scale = 0.12
ActiveSheet.View("ISO").Scale = 0.12
Case 900, 1000
ActiveSheet.View("FRONT").Scale = 0.10
7. Using the “View Set Centre” snippet position the Base view based on
the sheet width and height. This is done using the Sheet Width and
Sheet Height snippets.
ActiveSheet.View("FRONT").SetCenter(ActiveSheet.Width / 4,
(ActiveSheet.Height/3)*2)
8. Set the spacing between the top and side views to the front view using
the snippet “Spacing to other view”
ActiveSheet.View("TOP").SpacingBetween("FRONT") = -50
ActiveSheet.View("SIDE").SpacingBetween("FRONT") = 50
9. Use the “View from corner” snippet to position the ISO view from the
bottom right corner.
ActiveSheet.View("ISO").SetSpacingToCorner(-20,-70, SheetCorner.TopRight)
11.Back in the drawing create a section view (slice only) of the lock.
Ensure that the view sketch is fully constrained to the lock (once the
section view is placed, edit the section line and fully constrain the
sketch). If not, the section may move if the dimensions of the unit are
altered meaning that the section is out of position (when using
detailed views use the attach option on the right click menu for the
same reasons).
12.Using the “Suppress a View” and “View from corner” snippets, turn
on/off and position the section view based on whether the unit has
doors or not.
Else
ActiveSheet.View("A").View.Suppressed = True
End If
The first sheet adjusts to the size of the model. In this challenge, try to
automate the location and scale of the views within page 2.
Keep in mind that the reference to the model will be different to the first
page.
iLogic’s snippets allow users to swap out borders and title blocks from the
drawings own drawing resources or utilising a template file as a library.
For some companies these snippets are insufficient at which point coding is
required. An example of this is where a company wishes to delete current
drawing resources and replace them with the active border from a template
rather than a named one. The iLogic snippets will copy the drawing resource
from the template to the active document however may rename that resource
as “Copy of …” should one with an existing name exist. This can be controlled
using the KeepExtraResources snippet. If you set this property to False, a
resource is deleted when another resource replaces it. Deletion only happens
if the ResourceFileName is not blank. It is assumed that all the resources you
need can be found in the external resource file.
When writing a generic rule, a user can externalise it to make it available for
every drawing. The generic rule can therefore be treated in a similar fashion
to a sub or function. To pass the unique information required to the generic
rule, users can utilise name value maps. Rules can be run using these maps
to pass details from one rule to another, returning a value if needed.
Name value maps are created using the snippet called “RunRule (with map)”.
When this snippet is added to the code, 3 lines of text appear:
map.Add("Arg1", "Arg1Value")
iLogicVb.RunRule("ruleName", map)
The first line of code creates a new parameter map called map. This line does
not need altered unless a new name for that parameter is required.
The second line is used to add the required variables to the map to send to
the rule. E.g. if a user wants to send the x and y position to another rule the
would repeat the line for each variable:
The final line runs a rule and passes the map with its variables to the rule.
This can be either an internal or external rule e.g.
The value map exists in the code until it is clears of values, this is good
practice before using the map again:
Within the receiving rule the received values should be called. This is done by
referencing the named rules arguments e.g.
SymXR = RuleArguments("SymX")
SymXR = RuleArguments("SymY")
If you ever need to return a value from a rule with a named value map add
the following into the rule:
RuleArguments.Arguments.Value("oReturn") = oReturnValue
In the initial rule that sets the map, use the following before you clear the
map values to retrieve the returned value:
oReturnedValue = oBalloonScheme.Item("oReturn")
2. Either continue with the drawing from the last exercise or open UNIT –
EX3 START.dwg from the exercise 3 folder.
3. In the drawing, create a new rule named “ANY SHEET TITLE BLOCK
UPDATE”
4. Using the snippet “Resource File Name”, define a template file to use
for drawing resources. The template to be used is saved within the
templates folder in the project path and is named “Sym Std.dwg”. The
project workspace path can be referenced using the snippet named
“WorkspacePath” within the document snippets.
5. Set the code not to keep resources but replace them with ones from
the template by adding in the snippet “KeepDrawingResources”
ThisDrawing.KeepExtraResources = False
6. Use the snippet “Change Title Block” to swap the current title block
with the one named “Sym Title”
7. Set this rule to run for both sheets using the run rule snippet within
the sheet 1 and sheet 2 rules.
9. Create a new internal rule named “ANY SHEET ADD ASK SKETCHED
SYMBOL”
11.Add variables to the map with the following names and values:
b. "SymLib", "LIBRARY"
c. "SymX", (ActiveSheet.Width/10) / 2
e. "SymRot", 0
f. "SymScale", 1
13.Save and close the rule and set it to run within each Sheet rule
14.Within each sheets rule add code to run “GENERIC DELETE ILOGIC
CREATED” before running any other rules. This will delete placed
symbols from the last configuration before the symbol rule re-adds
them.
• Add to the rules to addin the symbol called “PHYSICAL SYM” just below
the symbol added in the previous exercise
• Create a sketched symbol library and save a new symbol within it. Using
the code from the previous exercise add that new symbol to your sheet.
A good example might be an arrow to show grain direction on the panel
on sheet 2.
Within iLogic rules, code can be written to access / utilise the API. Examples
of API function as well as a list of objects and methods can be found within
the Inventor help pages. The samples given in the API documentation are
written in VBA however are easily converted to work within vb.net and iLogic
projects.
In this class the ins and outs of using the API and programming techniques
are not covered.
When Automating drawings, viewing what is happening within a file can make
writing iLogic code much easier. For this users can use a simple VBA code
and the VBA watch window to interigate the model. More information on how
do to this can be found in the Autodesk University class: iLogic and the API.
Within Inventor, add the following code is added to the VBA editor:
VB.net doesn’t use Set statements and VBA does. The result is that these
words need to be removed when copying a sample into the iLogic window.
Many API examples can also be found on the Autodesk customisation forums.
These examples will often need adapted slightly to work with a user’s given
model or drawing however can give a strong indication of how their code
should look.
2. Either continue with the drawing from the last exercise or open UNIT –
EX4 START.dwg from the exercise 4 folder.
3. Add dimensions to the drawing if there are none already and ensure
that they are not centred.
6. Copy the code from the example. Note that you do not need the lines:
Public Sub CenterAllDimensions() or End Sub
7. Paste the code into a new external rule named “GENERIC CENTRE
DIMENSIONS”
9. Remove all the occurrences of “Set” from the code and run the rule.
Figure 1 - 3D Model
Each face in a design has several ways to reference it via code. There are
several methods to do this.
1) In Inventor 2019 we can use the new name face functionality in the part
environment. The named faces generate an attribute associated to it; this
is easily thought of as a hidden iproperty on the face. By searching the
model for this attribute users can reference the face.
2) Each face has an internal face ID that identifies the component. By
searching for this ID users can reference the required face.
Symetri have been using option 2 for users of Inventor 2018 or previous. For
2019 users option 1 works well. Should users want to use option 1 in older
releases the should download the Attribute Manager Utility. This utility is
available on the Autodesk blogs or from Eskin Solutions websites. For more
information on what attributes are please see
http://modthemachine.typepad.com/my_weblog/2009/07/introduction-to-
attributes.html
As the created code adds the annotations in, it important that we later can
search of these to be able to remove them. This is done by adding attributes
to the annotations that are created, allowing users to tag the dimension in a
searchable manor for later removal. By doing this, manually created
annotations can be left untouched when the model / drawing configuration is
changed. Again, a generic rule can be written to remove annotations that
have a certain attribute associated with them. E.g.
In Inventor 2019, users can name faces using the new “name face” command
within the part environment. These named faces can be shown via a label on
the new geometry tab in the iLogic browser. By naming the faces attributes
are created, these attributes can be searched for through the code to place
annotations.
In Inventor 2018 the name face command didn’t exist making it harder for
new users to reference faces. As a result, users had many other options
which are listed below:
8.1.3 Attributes
The Inventor API allows users to append data to objects within their designs.
Attributes are how a programmer stores nongraphical data on Inventor
objects to be used at a later point. You can append the following types of
data: integer, double, string, byte array, or any combination of these.
Attributes can be grouped into sets in the same way that iproperties are
grouped in tabs. Each attribute set can contain any number of attributes
however must have a unique name with respect to other attributes in that set
2. Either continue with the drawing from the last exercise or open UNIT –
EX5 START.dwg from the exercise 5 folder.
3. Open the assembly referenced by the model and edit the top panel.
5. Find the name of the panel’s top face and write it down.
7. Back in the drawing ensure sheet 1 is active and create a rule called
“SHEET 1 DIMENSIONS RULE”
8. Double click on the snippet RunRule (with map) from the std iLogic
snippets to add it to the rule.
12.Ensure that the value for oComp1AttName and oComp2AttName match the
ones that were stored earlier.
map.clear()
This will clear the map ready for its next use.
18. In the if statement create a loop to iterate between 1 shelf and the
total number of shelves in the model
For i = 1 To NO_SHELVES
Next
19.In the loop, add the dimension map code from above and alter to
create a dimension between the bottom face of the LHS and the top
face of the Shelf.
20.Change the value for oComp2PattNo to i so that the rule will loop
through each shelf:
21. Run the rule and ensure that the dimension for each shelf is created.
22.In the rule for sheet one, write a line to run the sheet 1-dimension
rule.
24.Change the configuration back again and rerun once the sheet 1 rule
again. The dimensions should be added or removed as the number of
shelves varies.
8.2.2 Balloons
26.Double click on the snippet RunRule (with map) from the std iLogic
snippets to add it to the rule.
31. As per steps 16 > 20, reference the number of shelves and door
configuration. If the NO_SHELVES > 0 and the door handing is
“NONE” add in the balloon code to reference the top face of the shelf.
Again, swap the pattern number for i
36.Test the rule by changing the model configuration and re running the
sheet 1 rule.
37.Swap to sheet 2 of the drawing. Add a hole table based on the base
view to the sheet. For many Automated drawings a hole table will
simplify the code and amount of automation required. Hole tables will
self-adjust based on the holes in a given view.
39.Using the same method as for the assembly dimensions create map
options with options shown below to dimension the extents of the LHS
panel. Note that the map options are different as a different external
rule will be referenced when generating part dimensions.
40.Copy and alter the code above to generate code to add dimensions in
for the panel width and depth.
41.Add dimensions in for the slot by altering the code above. The slot
dimensions should only be added if the LHS parameter
“GROOVE_REQUIRED” is true
DimPlaceMap.Add("oViewName","PANEL_FRONT")
DimPlaceMap.Add("oComp1AttName", "OUTSIDE_SLOT_FACE" )
DimPlaceMap.Add("oComp1Loc","")
DimPlaceMap.Add("oComp1Type","FACE")
DimPlaceMap.Add("oComp1EdgeNo",1)
DimPlaceMap.Add("oComp2AttName", "INSIDE_SLOT_FACE" )
DimPlaceMap.Add("oComp2Loc","")
DimPlaceMap.Add("oComp2Type","FACE")
DimPlaceMap.Add("oComp2EdgeNo",1)
DimPlaceMap.Add("oX", 0)
DimPlaceMap.Add("oY",-(ActiveSheet.View("PANEL_FRONT").Height / 10) - 1)
DimPlaceMap.Add("oType","")
DimPlaceMap.Add("oText","")
iLogicVb.RunExternalRule("GENERIC PART DIMENSION RULE", DimPlaceMap)
DimPlaceMap.Clear()
End If
42.Within the Sheet 2 rule run the external rule named “GENERIC ADD
CENTREMARKS”
Help Files: The Inventor help documentation contains a lot more information
than many give it credit for; especially when it comes to iLogic. Within the
help pages are examples of most of the iLogic snippets, help when referencing
the API as well as other dlls and products. On top of this, there is an
additional API help file that explains all the key concepts of programming
Inventor with guides and descriptions of all options. This help document is
accessed from the Inventor help menu:
In addition, there are many samples of code to aid new developers. This
document quickly becomes the main reference for what can and can’t be done
with the Inventor API.
YouTube: There are many iLogic videos on the web about iLogic automation.
Including some on drawing automation
https://www.youtube.com/watch?v=bcOvYc6rNUk
“My First Plug-in” is a self-paced tutorial guide for a smooth introduction into
the programming world. This is a “one-stop shop” learning path for users who
know Autodesk products but are absolutely new to programming and are
thinking about taking the plunge.
DevTV: https://www.autodesk.com/developer-network/platform-
technologies/inventor/overview
Training: Most VAR’s conduct regular iLogic and API programming training.
Many users find that these initial face to face courses are worth attending.
You can also take advantage of the Inventor API training materials stored in
Autodesk’s github repository: https://github.com/ADN-DevTech/Inventor-
Training-Material this material is self-paced and takes users through all the
main concepts of the API.
Should you need help applying any of this code or editing it to work with your
drawings please contact me chris.atherton@symetri.com or info@symetri.com
and we’ll endeavour to help.