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: 

Question on Running commands using API: how to provide 2 inputs through API?

13 REPLIES 13
Reply
Message 1 of 14
liminma8458
654 Views, 13 Replies

Question on Running commands using API: how to provide 2 inputs through API?

Hi

 

Brian Ekins gave a good information on how to Run Commands Using the API. And he also shows API can provide one sets of input to the command.

 

In my case, the Inventor command "analyze interference" need two sets of inputs. I tried to feed the commands with two selectset input throght API (see attached code). But the command looks like only take one set of them.So the behavior is not what I want.

 

So if it is possible,  how to provide 2 set of pre-defined input to inventor commands throught API?

 

Thank you very much for the help.

 

Limin

 

 

 

Thanks
Limin
Inventor pro 2023 64 bit update 2.1; Windows 10 pro 64 bit version 21H2; Office 2013 32 bit
13 REPLIES 13
Message 2 of 14
gavbath
in reply to: liminma8458

I believe the problem you are having here is because the dialog box still shows and wants you to select "OK."

As you can't provide the "OK" via the API, you can't complete the command.

 

In Brian Ekins' blog post he said this:

 

" Most commands, even if they support pre-selection of entities, will still allow additional selection so they will still require user input.  For example the Fillet command will take any pre-selected edges as input but still displays the dialog to allow the user to select more edges and specify any other options."

 

I don't think you can finish the analyze interference command through the API call.

Gavin Bath
MFG / CAM Technical Specialist
Design and Motion Blog
Facebook | Twitter | LinkedIn | YouTube


   

Message 3 of 14
gavbath
in reply to: liminma8458

Why not use the method that is already provided in the API rather than running the command using CommandManager?

 

AssemblyComponentDefinition.AnalyzeInterference( Set1 As ObjectCollection, [Set2] As Variant ) As InterferenceResults

Gavin Bath
MFG / CAM Technical Specialist
Design and Motion Blog
Facebook | Twitter | LinkedIn | YouTube


   

Message 4 of 14
liminma8458
in reply to: gavbath

The program runs well, but only take the first set to do the analysis. What I want is to analyse the first set against the second set.

Thanks
Limin
Inventor pro 2023 64 bit update 2.1; Windows 10 pro 64 bit version 21H2; Office 2013 32 bit
Message 5 of 14
liminma8458
in reply to: liminma8458

I want the highlight effect of the interference volumn as in the command. The API does not provide that

Thanks
Limin
Inventor pro 2023 64 bit update 2.1; Windows 10 pro 64 bit version 21H2; Office 2013 32 bit
Message 6 of 14
gavbath
in reply to: liminma8458

Get the InterferenceResult.InterferenceBody (which is a SurfaceBody) and display it using ClientGraphics?

Gavin Bath
MFG / CAM Technical Specialist
Design and Motion Blog
Facebook | Twitter | LinkedIn | YouTube


   

Message 7 of 14
liminma8458
in reply to: gavbath

Just wonder how to reach the object of "InterferenceResult.InterferenceBody", the Interferenceresult only shows centroid, occurrenceone,occurrencetwo, type and volume (double type). oResults.InterferenceBody returns error. as attached

 

How to do that? thanks

Thanks
Limin
Inventor pro 2023 64 bit update 2.1; Windows 10 pro 64 bit version 21H2; Office 2013 32 bit
Message 8 of 14
gavbath
in reply to: liminma8458

Try this:

 

Public Sub ShowInterference()

    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oCompDef As ComponentDefinition
    Set oCompDef = oDoc.ComponentDefinition
    
    Dim oSelect1 As ComponentOccurrence
    Set oSelect1 = oDoc.SelectSet.Item(1)
    Dim oSelect2 As ComponentOccurrence
    Set oSelect2 = oDoc.SelectSet.Item(2)
    
    Dim oCheckSet As ObjectCollection
    Set oCheckSet = ThisApplication.TransientObjects.CreateObjectCollection
    
    Call oCheckSet.Add(oSelect1)
    Call oCheckSet.Add(oSelect2)
    
    Dim oIntBody As SurfaceBody
    Set oIntBody = oDoc.ComponentDefinition.AnalyzeInterference(oCheckSet).Item(1).InterferenceBody
        
    ' Create the ClientGraphics object.
    Set oClientGraphics = oCompDef.ClientGraphicsCollection.Add("Sample3DGraphicsID")

        ' Create a new graphics node within the client graphics objects.
        Dim oSurfacesNode As GraphicsNode
        Set oSurfacesNode = oClientGraphics.AddNode(1)

        Dim oBody As SurfaceBody
        Set oBody = oIntBody

        ' Create client graphics based on the transient body
        Dim oSurfaceGraphics As SurfaceGraphics
        Set oSurfaceGraphics = oSurfacesNode.AddSurfaceGraphics(oBody)

        ' Update the view to see the resulting curves.
        ThisApplication.ActiveView.Update


End Sub

 

Select two components that interfere and then runthe routine. After you have run it, hide the 2 components and you'll see the interference body left over.

Gavin Bath
MFG / CAM Technical Specialist
Design and Motion Blog
Facebook | Twitter | LinkedIn | YouTube


   

Message 9 of 14
liminma8458
in reply to: gavbath

Set oIntBody = oDoc.ComponentDefinition.AnalyzeInterference(oCheckSet).Item(1).InterferenceBody

 

The above line does NOTwork. InterferenceBody is not recognized.  "oDoc.ComponentDefinition.AnalyzeInterference(oCheckSet).Item(1) " only has centroid, occurrenceone,occurrencetwo, type and volume (double).

 

More advise?

 

Thanks

Thanks
Limin
Inventor pro 2023 64 bit update 2.1; Windows 10 pro 64 bit version 21H2; Office 2013 32 bit
Message 10 of 14
gavbath
in reply to: liminma8458

I wouldn't post code on here if I hadn't tested it myself.... 🙂

 

1. Two interfering parts.1.JPG

 

2. Select them both

2.JPG

 

3. Run macro, interference is left behind

3.JPG

Gavin Bath
MFG / CAM Technical Specialist
Design and Motion Blog
Facebook | Twitter | LinkedIn | YouTube


   

Message 11 of 14
liminma8458
in reply to: gavbath

I add a definition line in your code: Dim oClientGraphics As ClientGraphics.

 

And create two parts as yours and make an assembly, want to repeat your success, still not working.

 

Stop at (see attached error massage): XXXXXX.....InterferenceBody

 

I am running on Inventor 2011. But I don't think this is a new feature if there is any.

 

Thanks

Thanks
Limin
Inventor pro 2023 64 bit update 2.1; Windows 10 pro 64 bit version 21H2; Office 2013 32 bit
Message 12 of 14
gavbath
in reply to: liminma8458

Very strange. I should have mentioned that I am using Inventor 2013 but I don't know if the InterferenceBody is new since 2011. I can't imagine it would be.

 

Maybe post your dataset and I'll try it in 2013.

Gavin Bath
MFG / CAM Technical Specialist
Design and Motion Blog
Facebook | Twitter | LinkedIn | YouTube


   

Message 13 of 14
gavbath
in reply to: liminma8458

I spoke to soon..... The InterferenceBody was new in Inventor 2012 sorry.

 

OH.JPG

Gavin Bath
MFG / CAM Technical Specialist
Design and Motion Blog
Facebook | Twitter | LinkedIn | YouTube


   

Message 14 of 14
liminma8458
in reply to: gavbath

Yes. The code works for Inventor 2013, but not 2011.

 

So I still have the question: is it possible to provide 2 inputs to run Inventor commands using API?     ^_^

 

Thanks

Thanks
Limin
Inventor pro 2023 64 bit update 2.1; Windows 10 pro 64 bit version 21H2; Office 2013 32 bit

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

Post to forums  

Autodesk Design & Make Report