Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Stabilize model name in drawing

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
1206 Views, 8 Replies

Stabilize model name in drawing

First off, newbie speaking here. I've searched around and surprisingly can't find a straightforward answer to my simple question below.

 

About to write my first iLogic code in a drawing. Before I get too deep I have an initial question. How do you "stabilize" the drawing's associated model so that the code will still work regardless of the model's name? This drawing will be copied (CopyDesign) along with the model. The model iLogic code will work because I've "stabilized" the browser nodes but that doesn't seem to work in drawings. I intend to have some drawing code that grabs info (parameters, iProps) from the assembly model so a stable connection between the drawing and model regardless of model name is essential.

 

I'm going to guess that I have to use additional code provided in iLogic to GET the model document name (code available under "Advanced Drawing API" and go from there. To do this do I have to incorporate a VBA "Dim" statement to hold the model name value or set it as a custom iProp in the drawing?

 

What I'm mainly looking to do is get the model info into the drawing where I can run some simple If/Then statements to manipulate the data as needed for the drawing. Just looking for some help to kick me off in the right direction when working with iLogic in drawings.

 

Thanks.

 

MechMan

8 REPLIES 8
Message 2 of 9
adam.nagy
in reply to: Anonymous

Hi,

 

Yes, that sounds correct, using the Advanced Drawing API:

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

MsgBox(modelName)

You don't usually even need the Dim keyword to declare a local variable. Sometimes you run into issues though when you explicitly have to declare the variable with the correct type, e.g.: 

Dim doc As PartDocument

These variables are only available while the Rule is running. If that's enough for you then no need to store it as an iProperty.

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 9
JBerns
in reply to: adam.nagy

@adam.nagy,

 

Does this "stabilize model name" method work with the new iLogic functionality introduced in Inv 2019?

 

Especially, the commands, Components.Add and Components.AddiPart?

 

Can iLogic change the browser name after it is added with the commands above?

 

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 4 of 9
marcin_otręba
in reply to: JBerns

Can iLogic change the browser name after it is added with the commands above?

 

compoccurrence.name ="" ' this will reset name to correct one if you need different just type it in to quotation marks

Message 5 of 9
JBerns
in reply to: marcin_otręba

@marcin_otręba,

 

Thanks for the code reference. Perhaps someone will post soon some iLogic samples with "stabilized browser names" and code that uses the component add and delete functions.

 

The goal is to have a master assembly in Vault (Basic) that gets design copied, necessary files renamed, check-out assembly, run the iLogic code to customize the design, and then check it all into Vault. Repeat for the next job.

 

Thanks again for sharing the info.

 

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 6 of 9
MjDeck
in reply to: JBerns

@JBerns, when using Components.Add, do you want the component name in the model browser to be exactly the same as the filename? It's easier if you don't.


Mike Deck
Software Developer
Autodesk, Inc.

Message 7 of 9
JBerns
in reply to: MjDeck

@MjDeck,

 

No. From what I have read, it is best that the browser name and filename do not match exactly.

 

This is the challenge that I am trying to understand/solve:

  • Create a master design (parts, assemblies, drawings, etc.) with iLogic rules/forms
  • Run the form/rules to create a unique design
  • Add the design to the Vault
  • Rename files in Vault to make them unique

What I am not sure is the best order for this workflow.

 

Then once the design is in the Vault, with the renamed files, will the form/rules work in the copied files after you have used Copy Design?

 

It would be great if you could use Vault's Copy Design and the rules would update to match the filenames, but that does not work - yet. So a generic filename is required in the browser. Just trying to get all these tools to work together.

 

 

Regards,

Jerry

 

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 8 of 9
marcin_otręba
in reply to: JBerns

Hi,

 

You always could use :

 

Dim ass As AssemblyDocument
ass = ThisApplication.ActiveDocument
Dim occ As ComponentOccurrence
Dim doc As Document


For Each occ In ass.ComponentDefinition.Occurrences

or
For Each doc In ass.AllReferencedDocuments

 

and use some rules for example

if doc.subtype = sheetmetal then

export dxf.

or give your files types or special marking using iproperties... you have plenty of options

Message 9 of 9
MjDeck
in reply to: JBerns

@JBerns, if you can can do all the required changes and run the rules for a particular configuration before you do the Copy Design, that makes it easier. Then you don't have to run the rules after the copy has been made and the filenames have been changed. But it sounds like that's not practical.

When you copy a design, do you follow a standard naming convention? Maybe you add the same prefix and suffix to all file names? If so, you can write the rules so that they add that prefix or suffix to all the hardcoded filenames. A parameter or iProperty in the assembly could hold the prefix or suffix.


Mike Deck
Software Developer
Autodesk, Inc.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report