surface to part creation

surface to part creation

Anonymous
Not applicable
808 Views
7 Replies
Message 1 of 8

surface to part creation

Anonymous
Not applicable

So I'm not asking about iLogic this time. 😉

I received a stp file from a vendor and would like to create individual part files from the surfaces that were imported. I have tried different methods of importing, but I can't seem to import it as an assembly model. I either get one huge part file period, or I get a bunch of surfaces and still only one part file.

Not sure my explanation is clear. On the model tree under origin, I get a "filename".stp, when opened list about 500ish little 3d box icons each with a name. I can change properties of each to alter its appearance, but can't copy/paste it to a blank part file. it gives an option to "export object" but that doesn't seem to do anything helpful. It also gives option to "Copy to Construction" again with no apparent result. Also "Copy Object" doesn't seem to do anything helpful. In the past, I've created sketches on surfaces to create parts from this type of file, but I was hoping with Inventor 2017, there would be an easier option. Thanks in advance for any and all help.

 

Frank

Inventor 2017

 

0 Likes
Accepted solutions (1)
809 Views
7 Replies
Replies (7)
Message 2 of 8

ekinsb
Alumni
Alumni

I think it should be possible to do something with the API to convert your part with multiple "pieces" into multiple parts.  Is it possible to share the STEP file, or another STEP file that is representative?  You can either email it directly to me or send me a link to where I can download it.  My email is brian.ekins@autodesk.com


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 8

Anonymous
Not applicable

Brian,

 

Just fired off the email wit zipped stp file. The native software this file came from was SolidWorks. Not sure if that makes a difference, but thought it might be helpful. Thanks again for your help.

 

 

Frank

 

Inventor 2017

 

0 Likes
Message 4 of 8

ekinsb
Alumni
Alumni

Here's a VBA program that exports every solid and surface in the active document to a new file.  There's a variable that specifies the folder where the new files will be written.  The filenames are the names of the solids or surfaces as they are displayed in the browser.

 

Public Sub ExportSurfaceModel()
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    
    Dim partDef As PartComponentDefinition
    Set partDef = partDoc.ComponentDefinition
    
    ' Define the directory to write the results.
    Dim targetDir As String
    targetDir = "C:\Temp\ExportResult\"
    
    ' Iterate over any solids.
    Dim solidBody As SurfaceBody
    Dim count As Integer
    count = 0
    For Each solidBody In partDef.SurfaceBodies
        count = count + 1
        ThisApplication.StatusBarText = "Processing solid " & count & " of " & partDef.SurfaceBodies.count & "..."
        Call CreateNewPart(targetDir & solidBody.Name & ".ipt", solidBody)
    Next
    
    ' Iterate over any surfaces.
    Dim workSurf As WorkSurface
    count = 0
    For Each workSurf In partDef.WorkSurfaces
        count = count + 1
        ThisApplication.StatusBarText = "Processing surface " & count & " of " & partDef.WorkSurfaces.count & "..."
        Dim surfBody As SurfaceBody
        Set surfBody = workSurf.SurfaceBodies.Item(1)

        Call CreateNewPart(targetDir & surfBody.Name & ".ipt", surfBody)
    Next

    ThisApplication.StatusBarText = "Completed processing."
End Sub

Private Sub CreateNewPart(filename As String, bodyInput As SurfaceBody)
    Dim newDoc As PartDocument
    Set newDoc = ThisApplication.Documents.Add(kPartDocumentObject, ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject), False)
    
    Dim baseFeatures As NonParametricBaseFeatures
    Set baseFeatures = newDoc.ComponentDefinition.Features.NonParametricBaseFeatures
    
    Call baseFeatures.Add(bodyInput)

    
    Call newDoc.SaveAs(filename, False)
    newDoc.Close
End Sub

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 5 of 8

Anonymous
Not applicable

Brian,

 

Thanks, as soon as I get a chance, I'll copy past this into a rule and give it a try. I don't have a target directory, I just want all the files in the folder the stp file is in. Nothing in this  code jumped out at me as the variable you mentioned, but VBA is not something I am familiar with, so no surprise there. I'll let you know how I make out. Thanks for your assistance.

 

Frank

Inventor 2017

 

0 Likes
Message 6 of 8

Anonymous
Not applicable

Brian,

 

Well that's a surprise, I found the variable for the target directory. All that remains is to rename all the "parts" as the file contains the name for surfaces as "none" "none1" thru "none584", this should be fun.

 

Thanks again

 

Frank

0 Likes
Message 7 of 8

Anonymous
Not applicable

Brian,

 

Sorry to be a pain, but am getting following error and I don't have any idea what it means

 

Error in rule program format:

All other Sub's or Function's must be after SubMain()

 

 

 

Line 1: All other Sub's or Function's must be after SubMain()

Line 1: Rule needs a SubMain() and EndSub

 

Thanks for your help.

 

Frank

0 Likes
Message 8 of 8

ekinsb
Alumni
Alumni
Accepted solution

Here's an iLogic rule version of the original VBA program.  Also, you didn't need to assign a name to those feature.  If you expand the "Surface Bodies" folder near the top of the browser, those are what are being written out and they have a name.

 

Public Sub Main()
    Dim partDoc As PartDocument = ThisApplication.ActiveDocument
    
    Dim partDef As PartComponentDefinition = partDoc.ComponentDefinition
    
    ' Define the directory to write the results.
    Dim targetDir As String
    targetDir = "C:\Temp\ExportResult\"
    
    ' Iterate over any solids.
    Dim count As Integer = 0
    For Each solidBody As SurfaceBody In partDef.SurfaceBodies
        count = count + 1
        ThisApplication.StatusBarText = "Processing solid " & count & " of " & partDef.SurfaceBodies.count & "..."
        CreateNewPart(targetDir & solidBody.Name & ".ipt", solidBody)
    Next
    
    ' Iterate over any surfaces.
    count = 0
    For Each workSurf As WorkSurface In partDef.WorkSurfaces
        count = count + 1
        ThisApplication.StatusBarText = "Processing surface " & count & " of " & partDef.WorkSurfaces.count & "..."
        Dim surfBody As SurfaceBody = workSurf.SurfaceBodies.Item(1)

        CreateNewPart(targetDir & surfBody.Name & ".ipt", surfBody)
    Next

    ThisApplication.StatusBarText = "Completed processing."
End Sub

Private Sub CreateNewPart(filename As String, bodyInput As SurfaceBody)
    Dim newDoc As PartDocument
    newDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, _
			 ThisApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), False)
    
    Dim baseFeatures As NonParametricBaseFeatures
    baseFeatures = newDoc.ComponentDefinition.Features.NonParametricBaseFeatures
    
    baseFeatures.Add(bodyInput)
    
    newDoc.SaveAs(filename, False)
    newDoc.Close
End Sub

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes