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: 

Fetch code to active document

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Covello_O
204 Views, 4 Replies

Fetch code to active document

Hi all

I' m struggling to fetch this code to the active document. I know it starts like this
Dim oDoc As ThisApplication.ActiveDocument
but then how to continue?

The code is as follow:

If  ThisDoc.Document.DocumentType = kDrawingDocumentObject Then
     MsgBox("Funtioniert nicht in der Zeichnung😊", vbInformation, "Nur .ipt oder .iam")
     Exit Sub
End If
'Dim oDoc As Document = ThisApplication.ActiveDocument
 
' 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

SavePath = "T:\my_\my_steps\"

Dim Rev As String = iProperties.Value("Project", "Revision Number")
If Rev = Nothing Then : Rev = "-" : End If

Dim oFullPath As String = ""

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") = ""
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
    Dim oData As DataMedium
    oData = ThisApplication.TransientObjects.CreateDataMedium
    oData.FileName = SavePath & ThisDoc.FileName(False) & "_" & Rev & ".stp"
	oFullPath = oData.FileName
oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
End If

'System.IO.Path.GetDirectoryName(SavePath) 
If System.IO.File.Exists(oFullPath) = True Then 
	MsgBox(ThisDoc.FileName(False) & "_" & Rev & ".stp" & _
	vbCrLf & "wurde erfolgreich in " & SavePath & " erstellt!", vbInformation, "😊 👍 🤘")
Else
    MsgBox("Da hat was nicht geklappt.😮"& vbCrLf &"Probiers nochmal.", vbCritical,"abbruch")	
End If

Any help would be very apreciated

Thank you

4 REPLIES 4
Message 2 of 5
A.Acheson
in reply to: Covello_O

Hi @Covello_O 

Can you indicate how your using the rule? Are you running it on one file or attempting to run it on multiple files? What is and isn't happening for you? 

You have this line commented out. When declared you should be able to do most things from the declared document object.

'Dim oDoc As Document = ThisApplication.ActiveDocument
 

 Later on your switching to the ilogic API which will access the objects differently than the Inventor API. Generally they target the document the rule is first run on and you can't switch documents later. 

 

ThisDoc.FileName(False)

 

And also your using the ilogic API iproperty snippets which are again specific to one document.

Dim Rev As String = iProperties.Value("Project", "Revision Number")

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 5
Covello_O
in reply to: A.Acheson

Hi thanks for your reply!

I use this code with the inventor form.

So when i want to make a step file from an active document i press that button it puts than directly to a predefined path .

I often have more than one document open. And when I switch from one active doc to another and I press the button again then i get the step file from the document that was active before. It doesen't take the active one. But when I go to the global rules right click and run rule than it takes the active one.

How can be fixed this?

Message 4 of 5
WCrihfield
in reply to: Covello_O

Hi @Covello_O.  When you are using an internal iLogic Form (internal means it is saved within the Inventor document), then that form will remain focused on the document it is saved within.  However, when you use a 'global' iLogic Form, it will focus on the document that was actively showing on your screen when you launched the form, and it will not change its focus to another document until you close the form, then reopen it.  If you opened a global iLogic form while one document was showing on your screen, then switched to another document while that form is still showing, it will not change its focus to that other document.  The global form would have to be closed, then opened again, while the document is showing on your screen that you want it to be working with.  That is just how they work.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5
Covello_O
in reply to: WCrihfield

Hi 

ok i thought that if I could reference the code to  thisApplication.ActiveDocument it would then refresh to the active doc. 

Many thanks

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report