import Step file into part

import Step file into part

AnJanson
Advocate Advocate
3,059 Views
12 Replies
Message 1 of 13

import Step file into part

AnJanson
Advocate
Advocate

Hi,

is there a possibility to import a step file into the current part document with iLogic?

The step file has multiple bodies or faces.

When i do it manually I create a new part file and run the import command with the following settings.

I would like to do the same thing automatically.

image.png

So far I was only able to open the step file via the TranslatorAddIn. But then I get an assembly.

Regards

Andreas

0 Likes
3,060 Views
12 Replies
Replies (12)
Message 2 of 13

chandra.shekar.g
Autodesk Support
Autodesk Support

@AnJanson,

 

Try below iLogic code to import step file into a existing part. Before running code, make sure that path of step file (highlighted in red color) is updated in below code.

Sub Main()
    Dim oDoc As PartDocument 
    oDoc = ThisApplication.ActiveDocument 

    Dim oPartCompDef As PartComponentDefinition 
    oPartCompDef = oDoc.ComponentDefinition 

    ' Create the ImportedGenericComponentDefinition bases on an Alias file 
    Dim oImportedGenericCompDef As ImportedGenericComponentDefinition 
    oImportedGenericCompDef = oPartCompDef.ReferenceComponents.ImportedComponents.CreateDefinition("path of step file\Sample.stp") 

    ' Set the ReferenceModel to associatively import the Alias file, set this property to False will just convert the 
    oImportedGenericCompDef.ReferenceModel = True 
    oImportedGenericCompDef.IncludeAll

    ' Import the Alias 
    Dim oImportedComp As ImportedComponent 
    oImportedComp = oPartCompDef.ReferenceComponents.ImportedComponents.Add(oImportedGenericCompDef) 
End Sub 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 13

YuhanZhang
Autodesk
Autodesk

Hi Andreas,

 

Here is a VBA sample code to import the STEP file into an existing part document(you need to change the step file path before running it):

 

Sub ImportSTEPToOpenPart()
   Dim sStepFile As String
   sStepFile = "C:\temp\new.stp"
      
   Dim oDoc As PartDocument
   Set oDoc = ThisApplication.ActiveDocument
   
   Dim oCompDef As PartComponentDefinition
   Set oCompDef = oDoc.ComponentDefinition
   
   Dim oICDef As ImportedGenericComponentDefinition
   Set oICDef = oCompDef.ReferenceComponents.ImportedComponents.CreateDefinition(sStepFile)
   oICDef.ImportedAssemblyOrganizationType = kImportedAsMultibodyPart
   
   Call oCompDef.ReferenceComponents.ImportedComponents.Add(oICDef)

End Sub

 

 

Hope it helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 4 of 13

AnJanson
Advocate
Advocate

Thanks for two solutions.

 

@YuhanZhang: The result is almost, what I want, but the postprocessing option stitch is missing.

The result is the same as if the option composite were chosen.

I would like to have the option stitch.

 

Part Options

  • Composite imports the assembly as a single composite feature in the part environment.
  • Individual imports the assembly as a single composite feature in the part environment.
  • Stitch (IGES and STEP files only) stitches several edge-matched surfaces or faces together.

How can I achieve this?

Is there any documentation available?

 

Regards

Andreas

0 Likes
Message 5 of 13

YuhanZhang
Autodesk
Autodesk

You can try the below code for your case:

 

oICDef.ImportedSurfaceOrganizationType = kImportedAsSingleCompositeFeature


If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 6 of 13

AnJanson
Advocate
Advocate

@YuhanZhang  schrieb:

You can try the below code for your case:

 

oICDef.ImportedSurfaceOrganizationType = kImportedAsSingleCompositeFeature

I tried, but the result is always the same.

In the pictures you can see the result I get through the API and below, the result if I import manually.

image.png

image.png

I have also attached my sample step file.

Do you have any other idea?

 

Regards Andreas

 

0 Likes
Message 7 of 13

YuhanZhang
Autodesk
Autodesk

The API can't get the same result as UI should be an issue, I log this issue as  INVGEN-22976, you can provide the number to query its status.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 8 of 13

Anonymous
Not applicable

@AnJanson

I know you get fom the 1st picture to the 2nd picture with the SCULPT command... (part env.)

0 Likes
Message 9 of 13

AnJanson
Advocate
Advocate

@Anonymous  schrieb:

@AnJanson

I know you get fom the 1st picture to the 2nd picture with the SCULPT command... (part env.)


 

Thanks for the hint, but I would like to do it automatically in one click. The result of the SCULPT command also differs because the faces are turned into one solid. The import and stitching command creates three separate solids.

0 Likes
Message 10 of 13

lzs013
Advocate
Advocate

How to import stl file to  open part?

0 Likes
Message 11 of 13

YuhanZhang
Autodesk
Autodesk

Here is a VBA sample to import STL to an open part document, change the STL file path before running it:

 

Sub ImportSTLIntoOpenPartSample()
    ' Get the STL translator.
    Dim oSTLTranslator As TranslatorAddIn
    Set oSTLTranslator = ThisApplication.ApplicationAddIns.ItemById("{81CA7D27-2DBE-4058-8188-9136F85FC859}")

    Dim oDataMedium As DataMedium
    Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
        
    ' Specify a STL file to import it into existing part document
    oDataMedium.FileName = "C:\Temp\MyData.stl"
    oDataMedium.MediumType = kFileNameMedium
 
    Dim oTranslationContext As TranslationContext
    Set oTranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
    oTranslationContext.Type = kFileBrowseIOMechanism
    
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    oTranslationContext.OpenIntoExisting = oDoc
    
    Dim oOptions As NameValueMap
    Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    
    Call oSTLTranslator.Open(oDataMedium, oTranslationContext, oOptions, oDoc)
End Sub


If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 12 of 13

AnJanson
Advocate
Advocate

@YuhanZhang  schrieb:

The API can't get the same result as UI should be an issue, I log this issue as  INVGEN-22976, you can provide the number to query its status.


Can you please tell me the status of this issue. I do not know where I can find it.

0 Likes
Message 13 of 13

YuhanZhang
Autodesk
Autodesk

We considered it in our backlog, you can try the Inventor 2021 build when it is available. You can also log in beta.autodesk.com to find the Alpha/Beta build info from it if you want to test Inventor before RTM build.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes