Вы находитесь на странице: 1из 52

DRAWING AUTOMATION

Hands-On Lab Handout


CHRIS ATHERTON
UK Consulting Services Manager | Symetri
Chris.Atherton@Symetri.com

REV A, AU LONDON 2018

Rev A, 06/06/2018 | Symetri | Page 1 of 52


Content

1 About ........................................................................................... 4

2 Summary of Lab ............................................................................ 5

3 Class Objectives ............................................................................ 6

4 Rule Structure ............................................................................... 7

4.1.1 Swapping sheets ............................................................ 8

4.1.2 Shared Variables ............................................................ 9

4.1.3 Open drawing and run rules ........................................... 10

4.1.4 Updating properties Model > Drawing ............................. 11

4.2 Exercise 1 ...................................................................... 13

4.2.1 Drawing iProperty Updates ............................................ 18

5 View Manipulation ........................................................................ 21

5.1 Exercise 2 ...................................................................... 24

5.2 Challenge ....................................................................... 26

6 Drawing Resources ...................................................................... 27

6.1.1 Named Value Maps ....................................................... 27

6.2 Exercise 3 ...................................................................... 30

6.2.1 Swap title blocks .......................................................... 30

6.2.2 Add Sketched Symbols.................................................. 30

6.3 Challenge ....................................................................... 32

7 API Code .................................................................................... 33

Rev A, 06/06/2018 | Symetri | Page 2 of 52


7.1.1 DebugObject VBA rule................................................... 34

7.2 Exercise 4 ...................................................................... 37

8 Dimensions & Balloons ................................................................. 38

8.1.1 2019 Example .............................................................. 40

8.1.2 2018 Example .............................................................. 40

8.1.3 Attributes .................................................................... 41

8.2 Exercise 5 ...................................................................... 42

8.2.1 Assembly Dimensions ................................................... 42

8.2.2 Balloons ...................................................................... 45

8.2.3 Part Component Dimensions .......................................... 48

9 Help and Resources...................................................................... 50

Help Files: ............................................................................. 50

Forums: ................................................................................ 50

YouTube: .............................................................................. 50

Blogs: ................................................................................... 51

My First Plugin: ...................................................................... 51

DevTV: ................................................................................. 51

Training: ............................................................................... 51

10 Appendix 1 – Generic Rules........................................................... 52

Rev A, 06/06/2018 | Symetri | Page 3 of 52


1 About
Managing Symetri’s UK Consulting Service Department, I oversee a team of
consultants that development and implement detailed Engineering solutions
for clients using Autodesk & Symetri products.

My Main focuses are Data management, where I specialise in the installation,


setup and management of Vault Professional, and Design Automation where I
have expertise in using iLogic within a company’s business workflows.

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.

Symetri is an Autodesk Platinum Partner and one of Autodesk’s leading


partners in Northern Europe. In the UK we are focussed particularly on
Engineering, Design and Manufacturing solutions, operating in the oil and gas,
transportation, nuclear and manufacturing sectors.

At Symetri we Challenge people to Work Smarter for a Better Future

Rev A, 06/06/2018 | Symetri | Page 4 of 52


2 Summary of Lab
In this lab, we will look at how to automate the various aspects of drawings
within Autodesk Inventor. We will show users how use standard snippets to
manipulate views based on the 3D geometry as well as a quick dive into the
API to look at how to further enhance the functionality to generate
dimensions and balloons. We will look at options using Autodesk Inventor
2019 new functionality as well as older methods utilising the API.

Rev A, 06/06/2018 | Symetri | Page 5 of 52


3 Class Objectives
• Start simple > build up fast
• Learn to use the standard iLogic snippets to automate a drawing
• Learn to interrogate a model from a drawing to automate aspects of the
sheet
• Learn to use the API samples to create more advanced functions
• Learn to use the new 2019 iLogic functionality to automate dimensions
• Learn how to find out if something is possible in Inventor Automation

Rev A, 06/06/2018 | Symetri | Page 6 of 52


4 Rule Structure
The preferred structure when it comes to drawings is to structure rules so
that either all sheets can be updated, or, a user can update an individual
sheet as required. By standardising the layout of the rules within the
drawings we make it easier to automate the running of the drawing
automation. As a secondary benefit it should be easier to diagnose problems
and to reuse code as external rules.

The following structure is recommended base on Symetri’s project experience


and used throughout this lab:

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

Rev A, 06/06/2018 | Symetri | Page 7 of 52


named C360_OnPublishDrawing as this name will be recognised on
Autodesk Configurator 360 as the rule to automatically run when a drawing is
requested.

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.

4.1.1 Swapping sheets

As part of this structure users need to swap to a named sheet when a


particular sheet rule is run. To do this the first of the drawing snippets are
used:

Access the active sheet in this drawing, as shown below

Make another sheet active

To activate a sheet, we can type: ActiveSheet = ThisDrawing.Sheet("<sheet


name>")

Rev A, 06/06/2018 | Symetri | Page 8 of 52


When running the top-level rule, users can store the active sheet and
reactivate it at the end. If this is not done then the last run sheet rule will
always be the active sheet after the drawing is configured.

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

4.1.2 Shared Variables

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.

Rev A, 06/06/2018 | Symetri | Page 9 of 52


Create, read, edit a shared Variable

Check the shared variable exists

Delete a named variable

Delete all shared variables in the current Inventor


Session

Shared variables are often used where information is retrieved and needs to
be stored for future use in multiple files.

4.1.3 Open drawing and run rules

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.

Rev A, 06/06/2018 | Symetri | Page 10 of 52


To open a model with the same name and location from the drawing users
can use:

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:

FullFilename = ThisDoc.Path & "\FINISHED_UNIT.dwg"


Dim oDrawingDoc As DrawingDocument = ThisApplication.Documents.Open(FullFilename)

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:

'run rule in the drawing document


auto = iLogicVb.Automation
'Run rule called C360_OnPublishDrawing in Drawing file
auto.RunRule(oDrawingDoc, "C360_OnPublishDrawing")

4.1.4 Updating properties Model > Drawing

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.

Dim oControlDef as ControlDefinition


oControlDef =
ThisApplication.CommandManager.ControlDefinitions.Item("UpdateCopiedModeliPropertiesCmd")
ocontroldef.execute

Rev A, 06/06/2018 | Symetri | Page 11 of 52


This code can then be triggered via the iLogic event triggers to run before saving
a drawing.

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.

Rev A, 06/06/2018 | Symetri | Page 12 of 52


4.2 Exercise 1

1. Ensure that Inventor is using project: AU Automation Lab.ipj

2. From the workspace open Unit.iam

3. From the iLogic Ribbon open the form called config.

4. Change the values


including number of
shelves and click update at
the bottom of the form. If
you are new to Autodesk
Inventor 2019 note that
levels of detail are not
used in this example.
Instead, the new snippets
allow components to be
dynamically added to the
model as required.

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

Rev A, 06/06/2018 | Symetri | Page 13 of 52


7. Place some views of the model: Front, Top, Side, Isometric and name
the views (please use capitals)

8. Create a second sheet and place the left side panel onto it. Again,
create a Front, Top and Side View (please use capitals).

9. Name your sheets: UNIT & LHS_PANEL

10.Create an iLogic rule called “C360_OnPublishDrawing”. This is the top-


level rule. Add a comment mark to the code window as a placeholder.

11.Create rules for each sheet. Add a comment to them as a placeholder

Rev A, 06/06/2018 | Symetri | Page 14 of 52


12.Create an outputs Rule. Add a comment as a placeholder.

13.Edit Rule C360_OnPublishDrawing and enter code to run the sheet 1,


sheet 2 and the outputs rule.

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.

Rev A, 06/06/2018 | Symetri | Page 15 of 52


15.Save and close the rule

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.

18.Add code to output the user parameters “DWF_WANTED” and


“PDF_WANTED” using the shared variable snippets under the variable
section of the standard iLogic snippets (see previous section for
information as to what these do):

If Parameter("DRAWING_WANTED") = True Then


SharedVariable("DWF_WANTED") = Parameter("DWF_WANTED")
SharedVariable("PDF_WANTED") = Parameter("PDF_WANTED")

SharedVariable.Remove("DWF_WANTED")
SharedVariable.Remove("PDF_WANTED")
End If

19.In-between the 4 lines of shared variables (gap shown in the above


picture) add code to access the drawing. Please change the drawing
path and name to suit your drawing:

FullFilename = ThisDoc.Path & "\UNIT.dwg"


Dim oDrawingDoc As DrawingDocument = ThisApplication.Documents.Open(FullFilename)

Rev A, 06/06/2018 | Symetri | Page 16 of 52


20.After these 2 lines of code add the code to run the drawing top level
rule. Please change C360_OnPublishDrawing to your top-level rule
name:

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.

If Parameter("DRAWING_WANTED") = True Then


SharedVariable("DWF_WANTED") = Parameter("DWF_WANTED")
SharedVariable("PDF_WANTED") = Parameter("PDF_WANTED")

FullFilename = ThisDoc.Path & "\UNIT.dwg"


Dim oDrawingDoc As DrawingDocument = ThisApplication.Documents.Open(FullFilename)

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.

If SharedVariable.Exists("PDF_WANTED") = True Then


Parameter("GEN_PDF") = SharedVariable("PDF_WANTED")
End If

Rev A, 06/06/2018 | Symetri | Page 17 of 52


If SharedVariable.Exists("DWF_WANTED") = True Then
Parameter("GEN_DWF") = SharedVariable("DWF_WANTED")
End If

If Parameter("GEN_PDF") = True Then


changedName = ThisDoc.ChangeExtension(".pdf")
ThisDoc.Document.SaveAs(changedName , True)
ThisDoc.Launch(changedName)
End If

If Parameter("GEN_DWF") = True Then


changedName = ThisDoc.ChangeExtension(".dwf")
ThisDoc.Document.SaveAs(changedName , True)
ThisDoc.Launch(changedName)
End If

25.Save and Close the drawing

26.From the 3d Model, open the form and test the options at the bottom
to update the drawing, output PDFs, Output DWFs

4.2.1 Drawing iProperty Updates

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”

Rev A, 06/06/2018 | Symetri | Page 18 of 52


29.Ensure that “Copy model iProperties” and “all properties” are ticked in
the dialogue box

Rev A, 06/06/2018 | Symetri | Page 19 of 52


30.Click ok out of all dialogues

31.Create a new rule named “UPDATE COPIED PROPS RULE”

32.Edit the rule and add the following code:

Dim oControlDef as ControlDefinition


oControlDef =
ThisApplication.CommandManager.ControlDefinitions.Item("UpdateCopiedModeliPropertiesCmd")
ocontroldef.execute

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.

Rev A, 06/06/2018 | Symetri | Page 20 of 52


5 View Manipulation
iLogic comes with plenty of code to help with drawing view manipulation.
Snippets exist to determine the height / width of a view, scale of a view,
required layers, suppression state and position of the view. This means that
to automate a drawing using the standard iLogic snippets requires a drawing
to be “pre-seeded” with the required views. Should a company’s workflow
require that drawings are created from scratch and views are actively created
by the iLogic code then current snippets will not suffice (please see the API
help samples).

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.

Rev A, 06/06/2018 | Symetri | Page 21 of 52


In order to access the model sizes and configuration, users are required to
reference the model’s parameters. These are accessed via the advanced
snippets. References are gathered from a model associated with a named
view or the base model for the drawing. Once determined the “Get a Model
Parameter” snippet will retrieve required values.

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

Rev A, 06/06/2018 | Symetri | Page 22 of 52


required parameter. By allowing iLogic to retrieve the name of the model the
actual referenced filename does not matter e.g.:

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.

Rev A, 06/06/2018 | Symetri | Page 23 of 52


5.1 Exercise 2

1. Ensure that Inventor is using project: AU Automation Lab.ipj

2. Either continue with the drawing from the last exercise or open UNIT -
EX2 START.dwg from the exercise 2 folder.

3. In the drawing create a new rule named SHEET 1 VIEWS RULE

4. Use the snippet named “Model Document Name” (in the iLogic
advanced drawing API snippets) to reference the model.

5. Using the snippet “Get a Model Parameter” to retrieve the


UNIT_HEIGHT, UNIT_WIDTH & UNIT_DEPTH parameters

'Get model name referenced by the base view of the drawing


UnitModelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)

'retrieve the dimensions from the model


UnitModelHeight = Parameter(UnitModelName, "UNIT_HEIGHT")
UnitModelWidth = Parameter(UnitModelName, "UNIT_WIDTH")
UnitModelDepth = Parameter(UnitModelName, "UNIT_DEPTH")

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

Rev A, 06/06/2018 | Symetri | Page 24 of 52


ActiveSheet.View("ISO").Scale = 0.05
End Select
End If

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)

10.In the model, change the configuration to include both doors.

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.

'suppress latch view if not needed


If Parameter(UnitModelName, "DOOR_HANDING") = "BOTH" Then
ActiveSheet.View("A").View.Suppressed = False
ActiveSheet.View("A").SetSpacingToCorner(- 140, - 70,
SheetCorner.BottomRight)

Else
ActiveSheet.View("A").View.Suppressed = True
End If

Rev A, 06/06/2018 | Symetri | Page 25 of 52


5.2 Challenge

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.

Rev A, 06/06/2018 | Symetri | Page 26 of 52


6 Drawing Resources
Drawing resources include title blocks, borders, sketched symbols, sketched
symbol libraries and AutoCAD blocks.

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.

Adding sketched symbols and AutoCAD blocks again requires coding, no


snippets exist. Luckily for new users, there are several samples in the API
help documentation that show how to add these features. This class will show
how to utilise some generic code written by Symetri to place these
annotations.

6.1.1 Named Value Maps

Many tasks when automating a drawing are repeatable, such as adding a


sketched symbol or creating a table. In these cases, it’s possible to write a

Rev A, 06/06/2018 | Symetri | Page 27 of 52


generic rule to do these tasks. In the example of placing a sketched symbol,
certain unique information is required to place and position it: Symbol name,
the symbol library it is stored in (new functionality in Inventor 2017), Position
in X, Position in Y, Rotation and Scale.

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:

Dim map As Inventor.NameValueMap =


ThisApplication.TransientObjects.CreateNameValueMap()

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:

map.Add("SymX", (ActiveSheet.Width/10)/2) 'X location for symbol


map.Add("SymY", (ActiveSheet.Height/10) - 1.5) 'Y location for symbol

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.

iLogicVb.RunRule("GENERIC Rule", map) 'run internal rule


iLogicVb.RunExternalRule("GENERIC Rule", map) 'run external rule

The value map exists in the code until it is clears of values, this is good
practice before using the map again:

Rev A, 06/06/2018 | Symetri | Page 28 of 52


map.clear()

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")

This method can be applied to many other situations.

Rev A, 06/06/2018 | Symetri | Page 29 of 52


6.2 Exercise 3
6.2.1 Swap title blocks

1. Ensure that Inventor is using project: AU Automation Lab.ipj

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.

ThisDrawing.ResourceFileName = ThisDoc.WorkspacePath() & "\Templates\Sym


Std.dwg"

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”

ActiveSheet.TitleBlock = "Sym Title"

7. Set this rule to run for both sheets using the run rule snippet within
the sheet 1 and sheet 2 rules.

6.2.2 Add Sketched Symbols

8. Ensure that the external rule named “GENERIC ADD SKETCHED


SYMBOLS” is accessible from the external rules tab.

9. Create a new internal rule named “ANY SHEET ADD ASK SKETCHED
SYMBOL”

Rev A, 06/06/2018 | Symetri | Page 30 of 52


10.Add the snippet “Run Rule (with Map)” to the rule and rename the
variable to SymScheme

Dim SymScheme As Inventor.NameValueMap =


ThisApplication.TransientObjects.CreateNameValueMap()

11.Add variables to the map with the following names and values:

a. "SymName", "ASK IF UNSURE"

b. "SymLib", "LIBRARY"

c. "SymX", (ActiveSheet.Width/10) / 2

d. "SymY", (ActiveSheet.Height/10) - 1.5

e. "SymRot", 0

f. "SymScale", 1

These should look in the form:

SymScheme.Add("SymName", "ASK IF UNSURE") 'name of symbol required


SymScheme.Add("SymLib", "LIBRARY") 'name of symbol library if it exists
SymScheme.Add("SymX", (ActiveSheet.Width/10)/2) 'X location for symbol
SymScheme.Add("SymY", (ActiveSheet.Height/10) - 1.5) 'Y location for symbol
SymScheme.Add("SymRot", 0) 'rotation of symbol
SymScheme.Add("SymScale", 1) 'scale of symbol

12.Reference the external rule “GENERIC ADD SKETCHED SYMBOLS” by


adding code to run this rule with the value map:

iLogicVb.RunExternalRule("GENERIC ADD SKETCHED SYMBOLS", SymScheme)

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.

iLogicVb.RunExternalRule("GENERIC DELETE ILOGIC CREATED")

Rev A, 06/06/2018 | Symetri | Page 31 of 52


6.3 Challenge

To build further on the exercise:

• 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.

• Create a new title block in the template document that incorporates a


prompted entry and use the code to place this on the drawing.

Rev A, 06/06/2018 | Symetri | Page 32 of 52


7 API Code
For those who are new to customising applications by writing programs, the
first question might be: what is this API thing that everyone talks about?

API, or Application Programming Interface, is a term used to describe the


functionality exposed by an application that allows it to be used through a
program. For example, you can use Inventor's API to write a program that will
perform the same types of operations you can perform when using Inventor
interactively. By using the API we can not only automate models and
drawings, but create new tools to increase functionality.
http://info.symetri.com/recorded-design-automation-webinar

The API can be accessed through multiple programming languages such as


VBA, VB.Net and C#. iLogic is written in vb.net, simplifying the code required
making it perfect for engineers to start coding rather than programmers to do
engineering.

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.

For many engineers starting out with drawing automation it is hard to


visualise how the API fits together as well as learn the techniques to build
their code. There is some great learning to be found online using Autodesk
University courses on this very subject.

15.iLogic and the API

16.Introduction to Inventor API Automation: Where Should You Start?

17.Inventor iLogic: Beyond the Basics

Rev A, 06/06/2018 | Symetri | Page 33 of 52


There’s a lot of complexity when using the API. iLogic tries to give easier
access for users through its interface. In Inventor 2018 and 2019, iLogic has
a new “auto-complete” or
“Intellisense” ability to aid users
with writing their code. As users
start typing, options are presented
to them. By typing “.” The next list of options is shown.

In this class the ins and outs of using the API and programming techniques
are not covered.

7.1.1 DebugObject VBA rule

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:

Public Sub DebugObject()


Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
Dim oObj As Object
Set oObj = oDoc.SelectSet.Item(1)
Stop
End Sub

Rev A, 06/06/2018 | Symetri | Page 34 of 52


Next, select an object such as a face, view, sheet or component in the
browser / graphics window. When done, running this macro will allow users
to see everything that makes up the selected object that can be accessed via
the API. In the following images a sheet has been selected. Within the VBA
window the properties of that sheet as well as objects that can be accessed
from it can be seen. For new users to the API, thinking of the API as a giant
tree diagram and using the VBA code to drive down that tree that make up an
object can make coding their rules easier.

Rev A, 06/06/2018 | Symetri | Page 35 of 52


When using VBA sample code from the API help within iLogic there are a few
differences in programming language that need to be addressed for the code
to work. iLogic will generally tell a user why their code is not running
however there are times where some guidance helps. Common changes are:

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.

VBA also writes statements without Parentheses around some arguments.


Within iLogic we are required to add these in e.g. MsgBox "This is a test."
Written in VBA is written as MsgBox("This is a test.") in iLogic rules.

More information and examples of these can be found in the Autodesk


University class: iLogic and the Inventor API

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.

Rev A, 06/06/2018 | Symetri | Page 36 of 52


7.2 Exercise 4

1. Ensure that Inventor is using project: AU Automation Lab.ipj

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.

4. Open the API help file:

5. Within the documentation find the sample to centre dimension text:


sample programs > Drawing > Annotations > Centre Dimension Text

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”

8. Apply the rule and view the error

9. Remove all the occurrences of “Set” from the code and run the rule.

Rev A, 06/06/2018 | Symetri | Page 37 of 52


8 Dimensions & Balloons
When manually creating dimensions or balloons in drawings, users select lines
and points representing faces on a drawing view to place the values and
balloons. The same is true when using iLogic.

Based on the faces that a dimension is required between, users need to


reference the lines in the drawing views that are generated from the face;
there may be multiple lines that represent that face. Drawing views are
created by Inventor constructing a clean representation of the 3D model on
top of the 2D sheet. This can be seen using a 3D connections Space Mouse
with an Iso button. When this button is clicked the drawing reorients in 3D to
show that the 2D view is actually a 3D representation of the visible lines of
the model. This is show in the images below:

Figure 2 - 2D View on drawing

Figure 1 - 3D Model

Figure 3 - Iso of Drawing View

Rev A, 06/06/2018 | Symetri | Page 38 of 52


Once the required line is found, a point is referenced (start, end, mid) as a
geometry intent. This geometry intent is used to tell Inventor the position to
reference the dimension. Once this intent is created the dimension or balloon
can be placed. Within the API help documentation, there are examples of
how to place all the main dimension types along with the theory behind this.

Code can be generically written to allow users to place dimensions or


balloons. This leaves the users to reference the face that they want to use,
as well as the position to place the annotation.

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.

Rev A, 06/06/2018 | Symetri | Page 39 of 52


' Get the active sheet from the active drawing.
Dim oDoc As DrawingDocument
oDoc = ThisServer.ActiveDocument

Dim oSheet As Sheet


oSheet = oDoc.ActiveSheet

' Iterate over all of the dimensions.


Dim oDim As DrawingDimension
For Each oDim In oSheet.DrawingDimensions
' Check to see if the dimension is a linear or angular dimension.
If oDim.AttributeSets.Nameisused("ilogic_Created") = True Then
' Center the text.
oDim.Delete
End If
Next
' Iterate over all of the dimensions.
Dim oBal As Balloon
For Each oBal In oSheet.Balloons
' Check to see if the dimension is a linear or angular dimension.
If oBal.AttributeSets.Nameisused("ilogic_Created") = True Then
' Center the text.
oBal.Delete
End If
Next

8.1.1 2019 Example

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.

8.1.2 2018 Example

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:

- Create attributes via code on selected faces


- Search for a face based on its internal ID
- Use the plugin called the Attribute Manager to enable a more interactive
selection of faces.

Rev A, 06/06/2018 | Symetri | Page 40 of 52


With any of these scenarios, generic code can be written to ensure that
referencing the data is made repeatable straight forward.

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

By adding an attribute to a face, it is possible to find that face using the


attribute manager. However, there is no direct user interface for adding
these until Inventor 2019 using the new name face command.

Rev A, 06/06/2018 | Symetri | Page 41 of 52


8.2 Exercise 5
8.2.1 Assembly Dimensions

1. Ensure that Inventor is using project: AU Automation Lab.ipj

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.

4. On the iLogic browser switch to the geometry tab

5. Find the name of the panel’s top face and write it down.

6. Do the same for the bottom face on the LHS panel

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.

9. Alter the line map.Add("Arg1", "Arg1Value"). Change Arg1 to


oViewName and Arg2Value to “FRONT”.

10.Copy this line and create more arguments as shown below


(alternatively drop these in from the custom snippets):

Map.Add("oViewName","FRONT") 'View name

Rev A, 06/06/2018 | Symetri | Page 42 of 52


Map.Add("oComp1Name", {"TOP"}) 'component 1 browser node name, to go down
the tree use {subName, Sub Name 2, Part Name}
Map.Add("oComp1AttName","Face1") 'Facename for the component
Map.Add("oComp1PattNo",1) 'element number from a pattern, use 1 if not in a
pattern
Map.Add("oComp1Loc","START") 'point to attach dim option are blank,
"START", "END", "MID"
Map.Add("oComp1Type","FACE") 'allows the user to specify a face, workplane,
workpoint, edge
Map.Add("oComp1EdgeNo",1) 'allows the users to specify which edge of a
given face they wish to use.
Map.Add("oComp2Name", {"LHS"}) 'component 2 browser node name
Map.Add("oComp2AttName","Face4") 'face 2 internal id from the find face
rule
Map.Add("oComp2PattNo",1) 'element number from a pattern, use 1 if not in a
pattern
Map.Add("oComp2Loc","START") 'point to attach dim option are blank,
"START", "END", "MID"
Map.Add("oComp2Type","FACE") 'allows the user to specify a face, workplane,
workpoint, edge
Map.Add("oComp2EdgeNo",1) 'allows the users to specify which edge of a
given face they wish to use.
Map.Add("oX",-1) 'specify the offset in the X direction from the view
centre
Map.Add("oY",0) 'specify the offset in the Y direction from the view centre
Map.Add("oType","Vertical") 'dimension type. Options are to leave
blank,"Horizontal","Vertical","Alligned")
Map.Add("oText","") 'Add any text that should appear after the dimension
value
Map.Add("oDimStyleName","") 'leave blank or specify the dimension style
name to be used

These arguments will be passed to a generic dimension rule to tell the


code what to dimension and where to place it.

11. Alter the line iLogicVb.RunRule("ruleName", map) so it calls an


external rule named "GENERIC ASSEMBLY DIMENSION RULE". It
should read: iLogicVb.RunExternalRule("GENERIC ASSEMBLY
DIMENSION RULE", Map)

12.Ensure that the value for oComp1AttName and oComp2AttName match the
ones that were stored earlier.

13.On the last line of the rule type:

map.clear()

This will clear the map ready for its next use.

14.Run the rule. A dimension should be created.

Rev A, 06/06/2018 | Symetri | Page 43 of 52


15.Repeat this process to create the horizontal dimension between the
RHS and LHS panels

16. In the dimension rule retrieve the parameters “DOOR_HANDING” and


“NO_SHELVES” from the model:

'Get model name referenced by the base view of the drawing


UnitModelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
DOOR_HANDING = Parameter(UnitModelName, "DOOR_HANDING")
NO_SHELVES = Parameter(UnitModelName, "NO_SHELVES")

17. Create an if Statement that will run if the NO_SHELVES is greater


than 0 and the DOOR_HANDING =”NONE”

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:

If NO_SHELVES > 0 And DOOR_HANDING = "NONE" Then


For i = 1 To NO_SHELVES
Map.Add("oViewName","FRONT") 'View name
Map.Add("oComp1Name", {"LHS"}) 'component 1 browser node
name, to go down the tree use {subName, Sub Name 2, Part Name}
Map.Add("oComp1AttName","FACE4") 'Facename for the component
Map.Add("oComp1PattNo",1) 'element number from a pattern,
use 1 if not in a pattern
Map.Add("oComp1Loc","") 'point to attach dim option are
blank, "START", "END", "MID"
Map.Add("oComp1Type","FACE") 'allows the user to specify a
face, workplane, workpoint, edge
Map.Add("oComp1EdgeNo",1) 'allows the users to specify which
edge of a given face they wish to use.
Map.Add("oComp2Name", {"SHELF"}) 'component 2 browser node
name
Map.Add("oComp2AttName","TOP") 'face 2 internal id from the
find face rule
Map.Add("oComp2PattNo",i) 'element number from a pattern,
use 1 if not in a pattern

Rev A, 06/06/2018 | Symetri | Page 44 of 52


Map.Add("oComp2Loc","") 'point to attach dim option are
blank, "START", "END", "MID"
Map.Add("oComp2Type","FACE") 'allows the user to specify a
face, workplane, workpoint, edge
Map.Add("oComp2EdgeNo",1) 'allows the users to specify which
edge of a given face they wish to use.
Map.Add("oX",0 - i) 'specify the offset in the X direction
from the view centre
Map.Add("oY",+1) 'specify the offset in the Y direction from
the view centre
Map.Add("oType","") 'dimension type. Options are to leave
blank,"Horizontal","Vertical","Alligned")
Map.Add("oText","") 'Add any text that should appear after
the dimension value
Map.Add("oDimStyleName","") 'leave blank or specify the
dimension style name to be used
iLogicVb.RunExternalRule("GENERIC ASSEMBLY DIMENSION RULE",
Map) 'external rule name
Map.Clear()
Next
End If

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.

23.Change the model configuration to alter the number of shelves and


rerun the sheet 1 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

25. Create a new rule called “SHEET 1 BALLOON RULE”

26.Double click on the snippet RunRule (with map) from the std iLogic
snippets to add it to the rule.

27.Alter the line map.Add("Arg1", "Arg1Value"). Change Arg1 to


oViewName and Arg2Value to “FRONT”.

28.Copy this line and create arguments as shown below (alternatively


drop these in from the custom snippets):

Rev A, 06/06/2018 | Symetri | Page 45 of 52


Map.Add("oViewName","FRONT") 'View name
Map.Add("oCompName", {"LHS"}) 'component 1 browser node name, to go down
the tree use {subName, Sub Name 2, Part Name}
Map.Add("oCompAttName","FACE1") 'Facename for the component
Map.Add("oCompPattNo",1) 'element number from a pattern, use 1 if not in a
pattern
Map.Add("oCompEdgeNo", 1) 'allows the users to specify which edge of a
given face they wish to use.
Map.Add("oX",-1) 'specify the offset in the X direction from the view
centre
Map.Add("oY",+1) 'specify the offset in the Y direction from the view
centre
iLogicVb.RunExternalRule("GENERIC ASSEMBLY BALLOON RULE", Map) 'external
rule name
Map.Clear()

29.Ensure that the oCompAttName value matches the name of the


outside face of the LHS panel in the model.

30.Run the rule and verify that a balloon is created

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

32.If the DOOR_HANDING is “RIGHT HAND” then ensure that a balloon is


created for the RHS Door

33.If the DOOR_HANDING is “LEFT HAND” then ensure that a balloon is


created for the LHS Door

34.If the DOOR_HANDING is “BOTH” then ensure that a balloon is created


for both doors and the lock.

If DOOR_HANDING = "NONE" And NO_SHELVES > 0 Then


For i = 1 To NO_SHELVES
Map.Add("oViewName","FRONT")
Map.Add("oCompName", {"SHELF"})
Map.Add("oCompAttName","TOP")
Map.Add("oCompPattNo",i)
Map.Add("oCompEdgeNo", 1)
Map.Add("oX",-1)
Map.Add("oY", + 1)
iLogicVb.RunExternalRule("GENERIC ASSEMBLY BALLOON RULE", Map)
Map.Clear()
Next
ElseIf DOOR_HANDING = "RIGHT HAND" Then
Map.Add("oViewName","FRONT")

Rev A, 06/06/2018 | Symetri | Page 46 of 52


Map.Add("oCompName", {"RHS_DOOR"})
Map.Add("oCompAttName","TOP")
Map.Add("oCompPattNo",1)
Map.Add("oCompEdgeNo", 1)
Map.Add("oX",-1)
Map.Add("oY", + 1)
iLogicVb.RunExternalRule("GENERIC ASSEMBLY BALLOON RULE", Map)
Map.Clear()
ElseIf DOOR_HANDING = "LEFT HAND" Then
Map.Add("oViewName","FRONT")
Map.Add("oCompName", {"LHS_DOOR"})
Map.Add("oCompAttName","TOP")
Map.Add("oCompPattNo",1)
Map.Add("oCompEdgeNo", 1)
Map.Add("oX",-1)
Map.Add("oY", + 1)
iLogicVb.RunExternalRule("GENERIC ASSEMBLY BALLOON RULE", Map)
Map.Clear()
ElseIf DOOR_HANDING = "BOTH" Then
Map.Add("oViewName","FRONT")
Map.Add("oCompName", {"RHS_DOOR"})
Map.Add("oCompAttName","TOP")
Map.Add("oCompPattNo",1)
Map.Add("oCompEdgeNo", 1)
Map.Add("oX",-1)
Map.Add("oY", + 1)
iLogicVb.RunExternalRule("GENERIC ASSEMBLY BALLOON RULE", Map)
Map.Clear()
Map.Add("oViewName","FRONT")
Map.Add("oCompName", {"LHS_DOOR"})
Map.Add("oCompAttName","TOP")
Map.Add("oCompPattNo",1)
Map.Add("oCompEdgeNo", 1)
Map.Add("oX",-1)
Map.Add("oY", + 1)
iLogicVb.RunExternalRule("GENERIC ASSEMBLY BALLOON RULE", Map)
Map.Clear()
Map.Add("oViewName","FRONT")
Map.Add("oCompName", {"LOK-522"})
Map.Add("oCompAttName","FRONT")
Map.Add("oCompPattNo",1)
Map.Add("oCompEdgeNo", 1)
Map.Add("oX",-1)
Map.Add("oY", + 1)
iLogicVb.RunExternalRule("GENERIC ASSEMBLY BALLOON RULE", Map)
Map.Clear()
End If

35. Add the balloon rule into the sheet 1 rule.

36.Test the rule by changing the model configuration and re running the
sheet 1 rule.

Rev A, 06/06/2018 | Symetri | Page 47 of 52


8.2.3 Part Component Dimensions

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.

38.Create a new rule called “SHEET 2 DIMENSION RULE”

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.

Dim DimPlaceMap As Inventor.NameValueMap =


ThisApplication.TransientObjects.CreateNameValueMap()
Map.Add("oViewName","PANEL_FRONT") 'View name
Map.Add("oComp1AttName", "Face0" ) 'Facename for the component
Map.Add("oComp1Loc","") 'point to attach the dim (blank, "START", "END", "MID")
Map.Add("oComp1Type","FACE") 'allows the user to specify a face /edge
Map.Add("oComp1EdgeNo",1) 'specify which edge of a given face to use.
Map.Add("oComp2AttName", "Face4" ) 'face 2 internal id from the find face rule
Map.Add("oComp2Loc","") 'point to attach the dim (blank, "START", "END", "MID")
Map.Add("oComp2Type","FACE") 'allows the user to specify a face/edge
Map.Add("oComp2EdgeNo",1) 'specify which edge of a given face to use.
Map.Add("oX", -3) 'specify the offset in the X direction from the view centre
Map.Add("oY",0) 'specify the offset in the Y direction from the view centre
Map.Add("oType","") 'dimension type. *blank*,"Horizontal","Vertical","Aligned")
Map.Add("oText","") 'Add any text that should appear after the dimension value
iLogicVb.RunExternalRule("GENERIC PART DIMENSION RULE", Map) 'external rule name
Map.Clear()

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

If Parameter(UnitModelName, "GROOVE_REQUIRED") = True Then


DimPlaceMap.Add("oViewName","PANEL_FRONT
DimPlaceMap.Add("oComp1AttName", "Face5" )
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) - 2)

Rev A, 06/06/2018 | Symetri | Page 48 of 52


DimPlaceMap.Add("oType","")
DimPlaceMap.Add("oText","")
iLogicVb.RunExternalRule("GENERIC PART DIMENSION RULE", DimPlaceMap)
DimPlaceMap.Clear()

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”

Rev A, 06/06/2018 | Symetri | Page 49 of 52


9 Help and Resources
As with any aspect of Inventor there is a lot of information available to help
users to learn the product.

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.

Forums: Autodesk have an Inventor customisation forum that is well used by


those utilising iLogic. Code can be found for most things a user would want to
accomplish. If not then it is easy to post a new question on how to achieve
what you need.

YouTube: There are many iLogic videos on the web about iLogic automation.
Including some on drawing automation
https://www.youtube.com/watch?v=bcOvYc6rNUk

Rev A, 06/06/2018 | Symetri | Page 50 of 52


Blogs: Most Autodesk VARs and Autodesk super enthusiasts maintain blogs
which provide hints, tips and samples of iLogic code that can help users.
These blogs tend to give more information about what the code is doing
allowing users to better apply it to their designs. On top of this Autodesk also
maintain their own technical blogs that provide examples of code with
explanations of how they work. https://www.autodesk.com/developer-
network/open

My First Plugin: https://knowledge.autodesk.com/search-


result/caas/simplecontent/content/my-first-inventor-plug-overview.html

“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

Introduction to Inventor Programming. A self-paced video tutorial


demonstrating how to get started developing with Autodesk Inventor.

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.

Rev A, 06/06/2018 | Symetri | Page 51 of 52


10 Appendix 1 – Generic Rules
Generic rules referenced by the examples in this document can be found
within the dataset for the Drawing Automation Lab. These should be available
from either the AU website or from Symetri:
http://info.symetri.com/autodesk-university-2018

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.

Rev A, 06/06/2018 | Symetri | Page 52 of 52

Вам также может понравиться