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: 

Save as .stp or .sat .

7 REPLIES 7
Reply
Message 1 of 8
mk92
675 Views, 7 Replies

Save as .stp or .sat .

Hello,

 

i use the code from this post: Shrinkwrap Using iLogic to create an ipt of my assembly. But i want to save this shrinkwrap as an .stp or .sat (defined by a Parameter).

How can i add this to the code?

 

Regards

7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: mk92

I copied these export examples straight from the iLogic Snippets. If you haven't seen those before, check em out. The picture I attached shows where to find them in the iLogic dialog.

 

You'd just need an if statement to make them run based on your parameter, which I named STPorSAT, but you can rename it to whatever you like.

 

 

If Parameter("STPorSAT")="STP" Then

' 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 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 = ThisDoc.PathAndFileName(False) & ".stp" oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData) End If

ElseIf Parameter("STPorSAT")="SAT" Then
' Set reference to active document.
oDoc = ThisApplication.ActiveDocument
' Check the Document type is an assembly or part
If (oDoc.DocumentType <> kAssemblyDocumentObject And _ oDoc.DocumentType <> kPartDocumentObject) Then
MsgBox("Error:Document type is not assembly/part")
Exit Sub
End If

' Get document's full file name
sFname = ThisDoc.PathAndFileName(False) & ".sat"
' Do a 'Save Copy As' to SAT forma
oDoc.SaveAs(sFname, True)
End If

 

Message 3 of 8
mk92
in reply to: Anonymous

Thanks for your answere. I know the snippets, but i dont have a idea where to put your code in the code from the link i posted.

 

The Problem is the shrinkwrap the code does isnt opend in Inventor. Alls this happend in the background. So where do i have to put your code in the code from the link? Or do i have to change the whole code?

 

I want to do:

 

1. Do the shrinkwrap

2. then check if .stp or .sat is choosen

3. save in the shrinkwrap as sat or step

Message 4 of 8
Anonymous
in reply to: mk92

I think all you would need to add would be the step in bold:

 

1. do the shrinkwrap (using your code)

1a. Open the shrinkwrap file (I believe there is a snippet already for opening. Something like Launch Document and then you'd just use the filename you create in the shrinkwrap code)

2. check for stp or sat

3. write out file

 

I'm not able to go through it at the moment, but I think that should get you headed in the right direction.

Message 5 of 8
mk92
in reply to: Anonymous

Okay i have done that. But now there is another problem. 

 

The shrinkwrap works fine and the file opens. But in the shrinkwrap file there are no rules and parameters. How can i use my rule in the source part to save the shrinkwrap file as step or sat? 

 

 

Message 6 of 8
Anonymous
in reply to: mk92

Good question. 

 

We should re-order the steps, I think.

 

1. Get value of parameter STPorSAT while in the original file and store it ina variable to be used later in the if statement that decides which format to export.

 

Example

Dim strSTPorSAT as String
strSTPorSAT = Parameter("STPorSAT")

2. do the shrinkwrap (using your code)

3. Open the shrinkwrap file (I believe there is a snippet already for opening. Something like Launch Document and then you'd just use the filename you create in the shrinkwrap code)

4. write out file, but we need to change the if statement to point to the variable from step 1

 

If strSTPorSAT="STP" Then
	'Previous STP code
ElseIf strSTPorSAT="SAT" Then
	'Previous SAT code
End If

 

Would that work?

Message 7 of 8
mk92
in reply to: Anonymous

Up to point 4 its all clear, but then, when the new file opens. The file wich contains the rule is in the background and the shrinkwrap is the active file. So the rule in the original part doesn't work anymore!

 

So i have to the save as in the background, correct me if i am wrong.

 

So there has to be a way to create directly a step or sat file.

 

So instead of:

 

Call SET_COUNT()  'COUNT = 8

    ThisApplication.SilentOperation = True
    oPartDoc.SaveAs(ShrinkwrapFileName, False)
    ThisApplication.SilentOperation = False

 

It has to be something like yours:

 

If Parameter("STPorSAT")="STP" Then

' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7​F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslation​Context
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMa​p

If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplicati​on.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 = ThisDoc.PathAndFileName(False) & ".stp"
oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveD​ocument, oContext, oOptions, oData)
End If

ElseIf Parameter("STPorSAT")="SAT" Then
' Set reference to active document.
      oDoc = ThisApplication.ActiveDocument 
      ' Check the Document type is an assembly or part
      If (oDoc.DocumentType <> kAssemblyDocumentObject And _ oDoc.DocumentType <> kPartDocumentObject) Then
            MsgBox("Error:Document type is not assembly/part")
            Exit Sub
      End If 

' Get document's full file name
sFname = ThisDoc.PathAndFileName(False) & ".sat"
' Do a 'Save Copy As' to SAT forma
oDoc.SaveAs(sFname, True)
End If

 

But it must happend directly with the shrinkwrap file in the background. So the original 3D modell remains active.

 

Message 8 of 8
mk92
in reply to: Anonymous

Works fine until point 4. There the original part isnt the active part so the shrinkwrap is opend and is active.

 

I have to do exactly the same as in the Rule from my link in the first post.

 

Until this point:

 

Call SET_COUNT()  'COUNT = 8

    ThisApplication.SilentOperation = True
    oPartDoc.SaveAs(ShrinkwrapFileName, False)
    ThisApplication.SilentOperation = False

 Then instead of oPartDoc.SaveAs.....i need to do what you send me:

If strSTPorSAT="STP" Then
	'Previous STP code
ElseIf strSTPorSAT="SAT" Then
	'Previous SAT code
End If

 

So the active document has to be the original assembly, not the ahrinkwrap.

 

I usw exactly the code from this link:

Shrinkwrap with iLogic

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

Post to forums  

Autodesk Design & Make Report