Define envelope (assembly) vba automation

Define envelope (assembly) vba automation

Anonymous
Not applicable
1,029 Views
7 Replies
Message 1 of 8

Define envelope (assembly) vba automation

Anonymous
Not applicable

Hello,
we send very often assmeblies to other companies and we have to envelope some parts with the "simplify tab".
https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2017/ENU/Inventor-Help/files/G...

I already added a custom ipropertie to all parts that marks them as needed or not needed for export.
Now I want to define envelopes by VBA (API). But I can not find any information for it? Maybe it isnt availible in the API?!
Any keywords, hints or ideas?

I thouht to something like that would be possible (simple version):

For Each oPart in Assembly
If  custom ipropertie "Envelope" = Yes Then
oPart.Envelope = True
End If
Next


Thanks for any help.

0 Likes
1,030 Views
7 Replies
Replies (7)
Message 2 of 8

YuhanZhang
Autodesk
Autodesk

The Envelope function is provided by the BIM Simplify addin, now we don't have an API to do it directly, but the function is to create a client graphics block for a part component, so you can try to create your own client graphics(in a client feature) for it.



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 3 of 8

Anonymous
Not applicable

Could you pleas explain it a little bit more?
What do you mean with "own client graphics (in a client feature)?

0 Likes
Message 4 of 8

YuhanZhang
Autodesk
Autodesk

The addin defines the Envelope using the client graphics in a client feature, that means you can create a similar by yourself, below is a simple VBA code sample for it:

 

Sub CreateEnvelopeSample()
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oCompDef As AssemblyComponentDefinition
    Set oCompDef = oDoc.ComponentDefinition
    
    Dim oClientFeatures As ClientFeatures
    Set oClientFeatures = oCompDef.Features.ClientFeatures
    
    Dim oOccu As ComponentOccurrence
    Set oOccu = ThisApplication.CommandManager.Pick(kAssemblyOccurrenceFilter, "Select an occurrence in assembly")
    
    Dim oRangeBox As Box
    Set oRangeBox = oOccu.RangeBox
    
    If oRangeBox.MinPoint.DistanceTo(oRangeBox.MaxPoint) > 0.000001 Then
        
        Dim oTransientBrep As TransientBRep
        Set oTransientBrep = ThisApplication.TransientBRep
        
        Dim oEnvelopeBody As SurfaceBody
        Set oEnvelopeBody = oTransientBrep.CreateSolidBlock(oRangeBox)
        
        Dim oClientFeaDef As ClientFeatureDefinition
        Set oClientFeaDef = oClientFeatures.CreateDefinition("Envelope")
        
        Dim oClientFea As ClientFeature
        Set oClientFea = oClientFeatures.Add(oClientFeaDef, "MyEnvelope")
        
        Set oClientFeaDef = oClientFea.Definition
        
        Dim oClientGraphics As ClientGraphics
        Set oClientGraphics = oClientFeaDef.ClientGraphicsCollection.Add("Envelope")
        
        Dim oGraphicsNode As GraphicsNode
        Set oGraphicsNode = oClientGraphics.AddNode(oClientGraphics.Count + 1)
        
         Call oGraphicsNode.AddSurfaceGraphics(oEnvelopeBody)
         
         oOccu.Visible = False
         oDoc.Update
         
    End If
    
End Sub

 

 

You can use it as a start to create a function to define your own envelopes. Hope this 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.

0 Likes
Message 5 of 8

Anonymous
Not applicable

Thank you. I tried your code sample and it works to create envelops. But this kind of envelops aren't be able to export into the dataformat step?! And I need it for exporting into step for customers.
Can it be exported with other settings? If, this could be a solution.

0 Likes
Message 6 of 8

YuhanZhang
Autodesk
Autodesk

What's your purpose? Export the data to some other CAD format to allow your customers to only view them(in 3D viewer) and hide your detailed design to protect your design?  If so the client graphics currently can't be exported to STEP file, and I think you can try below code:

 

Sub CreateEnvelopeSampleInPart()
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oCompDef As AssemblyComponentDefinition
    Set oCompDef = oDoc.ComponentDefinition
    
    Dim oOccu As ComponentOccurrence
    Set oOccu = ThisApplication.CommandManager.Pick(kAssemblyLeafOccurrenceFilter, "Select an occurrence in assembly")
    
    Dim oPart As PartDocument
    Set oPart = oOccu.Definition.Document
     
    Dim oRangeBox As Box
    Set oRangeBox = oPart.ComponentDefinition.RangeBox
    
    If oRangeBox.MinPoint.DistanceTo(oRangeBox.MaxPoint) > 0.000001 Then
        oRangeBox.Expand 0.001
        
        Dim oTransientBrep As TransientBRep
        Set oTransientBrep = ThisApplication.TransientBRep
        
        Dim oEnvelopeBody As SurfaceBody
        Set oEnvelopeBody = oTransientBrep.CreateSolidBlock(oRangeBox)

         Dim oEnvelope As NonParametricBaseFeature
         Set oEnvelope = oPart.ComponentDefinition.Features.NonParametricBaseFeatures.Add(oEnvelopeBody)
         
         If Not oEnvelope.IsSolid Then
            Dim oSurface As SculptSurface
            Set oSurface = oPart.ComponentDefinition.Features.SculptFeatures.CreateSculptSurface(oPart.ComponentDefinition.WorkSurfaces(oPart.ComponentDefinition.WorkSurfaces.Count), kSymmetricExtentDirection)
            
            Dim oCol As ObjectCollection
            Set oCol = ThisApplication.TransientObjects.CreateObjectCollection
            
            oCol.Add oSurface
            
            Dim oSculpt As SculptFeature
            Set oSculpt = oPart.ComponentDefinition.Features.SculptFeatures.Add(oCol, kJoinOperation)
         End If
         
         oDoc.Update
    End If
    
End Sub

 

 

After running the code you can export your assembly to STEP file, and unsave the changes. Hope this works for you.



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 7 of 8

Anonymous
Not applicable

@YuhanZhang wrote:

What's your purpose? Export the data to some other CAD format to allow your customers to only view them(in 3D viewer) and hide your detailed design to protect your design? 


Exactly. Customers and suppliers.

Your code works, if used in parts. But this workarround doesn't save use time, because we have to check each part in each assembly, if it can be shown detailed or not. A vba code could do that job, but thats would take a lot of time in big assemblies with many parts and assemblies with subassemblies and so on.
I think we can do it faster by hand. Because we only need to select the parts or assembly in the main assembly and make the envelope.


Your idea was good.
Sadly the simplify plugin doesnt have API.
Thanks anyway for your nice support!

 

0 Likes
Message 8 of 8

YuhanZhang
Autodesk
Autodesk

The sample code is to demonstrate how to create envelope for a selected occurrence in assembly, you need to enhance it to iterate all the occurrences and check if you need to create the envelope for them, so you need not to do any manual work then.



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