Avoid applying rule to all subassemblies

Avoid applying rule to all subassemblies

YannickEnrico
Advisor Advisor
530 Views
9 Replies
Message 1 of 10

Avoid applying rule to all subassemblies

YannickEnrico
Advisor
Advisor

Hey there.

I managed to string together a piece of ilogic to generate stepfiles and copy them to a secondary location which runs when I save or close my assembly.

However, it seems to cycle through all subassemblies, while I only want the current assembly (top level) to be generated.

 

I've cut out the last lines defining locations for the step files. My understanding is that it's tied to "ThisApplication.ActiveDocument", but I'm not sure what the alternative is?


Thanks in advance.

 

' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    Dim oData As DataMedium
    oData = ThisApplication.TransientObjects.CreateDataMedium
    oData.FileName = ThisDoc.PathAndFileName(False) & ".stp"
If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
    ' Set application protocol.
    ' 2 = AP 203 - Configuration Controlled Design
    ' 3 = AP 214 - Automotive Design
    oOptions.Value("ApplicationProtocolType") = 3
    ' Other options...
    'oOptions.Value("Author") = ""
    'oOptions.Value("Authorization") = ""
    'oOptions.Value("Description") = ""
    'oOptions.Value("Organization") = "APMØLLERMÆRSK"
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
End If

 Dim oDocument As Document
     oDocument = ThisApplication.ActiveDocument

 

 

_______________________________________________________________________________________
Intel Core i9-14900KF
64 GB DDR5 6000 MHz
2TB WD_BLACK
RTX A4000
------------------------------
Inventor 2026 Professional
0 Likes
Accepted solutions (1)
531 Views
9 Replies
Replies (9)
Message 2 of 10

Cadkunde.nl
Collaborator
Collaborator

The code you show does not cycle through all documents.

Did you add this as an event before save on all documents?

Or did you not show full code

0 Likes
Message 3 of 10

YannickEnrico
Advisor
Advisor

The remaining portion of the code is just the copy of the newly generated file

 

I guess it comes down to me changing things in a sub assembly from top level assembly, and when it asks whether it should save all the parts and assemblies, it runs on that assembly save as well?

 

The event trigger:

 

YannickEnrico_0-1681810890301.png

 

_______________________________________________________________________________________
Intel Core i9-14900KF
64 GB DDR5 6000 MHz
2TB WD_BLACK
RTX A4000
------------------------------
Inventor 2026 Professional
0 Likes
Message 4 of 10

Cadkunde.nl
Collaborator
Collaborator

yes it will activate in every document you save if you use a rule.

 

But the thing is, you use:

ThisApplication.ActiveDocument

So the documents that are saved, which are not the active document, still make a step of the active document.

Thats what your code says while running in any saved document.

 

That could explain why you experience the step being generated several times. 

0 Likes
Message 5 of 10

Cadkunde.nl
Collaborator
Collaborator

Alternative ou can use. Thisdoc.document

This will make a step of the document being saved

0 Likes
Message 6 of 10

YannickEnrico
Advisor
Advisor

It's not that the step is generated several times, but that steps are generated of each subassembly.

 

But Thisdoc.Document only engages the active document, even if several subassemblies are saved as well?

_______________________________________________________________________________________
Intel Core i9-14900KF
64 GB DDR5 6000 MHz
2TB WD_BLACK
RTX A4000
------------------------------
Inventor 2026 Professional
0 Likes
Message 7 of 10

Cadkunde.nl
Collaborator
Collaborator

Thisdoc.document = the document from which the rule is run

Thisapplication.activedocument = the document that is currently active in inventor.

It can be different.

 

you can try:

 

If Not thisdoc.document is Thisapplication.activedocument Then

exit sub

End If

 

This way it will only trigger in the active document on save.

0 Likes
Message 8 of 10

Cadkunde.nl
Collaborator
Collaborator
oData.FileName = ThisDoc.PathAndFileName(False) & ".stp"

Checked your code, because of this line, you get a step file for each document saved (Thisdoc)

 

But each step file is the same (thisapplication.document)

0 Likes
Message 9 of 10

Cadkunde.nl
Collaborator
Collaborator
Accepted solution

for completion, this is I think what you want:

 

If Not ThisDoc.Document Is ThisApplication.ActiveDocument Then
	Exit Sub
End If


Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium
oData.FileName = ThisDoc.PathAndFileName(False) & ".stp"
If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
	' Set application protocol.
	' 2 = AP 203 - Configuration Controlled Design
	' 3 = AP 214 - Automotive Design
	oOptions.Value("ApplicationProtocolType") = 3
	' Other options...
	'oOptions.Value("Author") = ""
	'oOptions.Value("Authorization") = ""
	'oOptions.Value("Description") = ""
	'oOptions.Value("Organization") = "APMØLLERMÆRSK"
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

	oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
	MsgBox(ThisApplication.ActiveDocument.fullfilename)
End If
0 Likes
Message 10 of 10

YannickEnrico
Advisor
Advisor

That worked. Thanks

 

The code is stolen directly from the preinstalled custom snippets, and my only changes relate to naming and placing of files.

 

I had not considered those two differences you mentioned above.

_______________________________________________________________________________________
Intel Core i9-14900KF
64 GB DDR5 6000 MHz
2TB WD_BLACK
RTX A4000
------------------------------
Inventor 2026 Professional
0 Likes