Hello all,
I love the new triad function when placing a new part in Inventor 2014:
I am now searching to trigger the same function for a part that already has been placed.
Something like:
1) select component
2) press a button (triggers the macro I now want to write)
3) the triad pops up.
I searched true the Inventor Help & what's new in the API. But didn't find any reference to that command. So I am afraid that it is not yet in the API. Could I maybe emulate it by replacing a component with itself using the place component command + emulating a mouseclick at the same origin as the original piece?
So a piece of code like:
1) get filelocation of selected part
2) get the origin point (x,y,z) of the part
3) get the translation between the origin of the assembly and the part
4) delete the selected part
5) place the part using the place component command (so the triad has been triggered)
6) fill in the filelocation, origin & translation
7) give control back to the user so he can move the part using the triad.
Before I start I just want to know there is no easier method? Cause I believe I will have a few hours of coding and debugging in front of me if I try the above.
thank you!
Chris
Hi Chris,
This is just an idea.
Using ClientGraphics you could create the custom triad from 3 colored arrows ( ~ 3D indicator) and place it into desired position relative to component's coordinate system. You may place axes names as well.
Here is VBA code that generates this arrow in the active part document.
'////////////////////////////////////////////////////////////////// '// SurfaceGraphics Sample '// Please open a part document '////////////////////////////////////////////////////////////////// Public Sub DrawSurfaceGraphics() Dim oDoc As Document Set oDoc = ThisApplication.ActiveDocument Dim oCompDef As ComponentDefinition Set oCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oCoordSet As Object Dim oGraphicsNode As Object 'get datasets, dataset, graphics node Call getCG(oGraphicsNode, oCoordSet) Dim oTransientBRep As TransientBRep Set oTransientBRep = ThisApplication.TransientBRep ' Create a point representing the center of the bottom of the cone Dim oBottom As Point Set oBottom = ThisApplication.TransientGeometry.CreatePoint(0, 0, 0) ' Create a point representing the tip of the cone Dim oTop As Point Set oTop = ThisApplication.TransientGeometry.CreatePoint(0, 10, 0) ' Create a transient cone body Dim oBody As SurfaceBody Set oBody = oTransientBRep.CreateSolidCylinderCone(oBottom, oTop, 5, 5, 0) ' Reset the top point indicating the center of the top of the cylinder Set oTop = ThisApplication.TransientGeometry.CreatePoint(0, -40, 0) ' Create a transient cylinder body Dim oCylBody As SurfaceBody Set oCylBody = oTransientBRep.CreateSolidCylinderCone(oBottom, oTop, 2.5, 2.5, 2.5) ' Union the cone and cylinder bodies Call oTransientBRep.DoBoolean(oBody, oCylBody, kBooleanTypeUnion) ' Create client graphics based on the transient body Dim oSurfaceGraphics As SurfaceGraphics Set oSurfaceGraphics = oGraphicsNode.AddSurfaceGraphics(oBody) ThisApplication.ActiveView.Fit ThisApplication.ActiveView.Update Beep End Sub '////////////////////////////////////////////////////////////////// '// get the owner of the client graphics for primitive '// part,assembly --> ComponentDefinition '// drawing ---> active sheet '////////////////////////////////////////////////////////////////// Private Sub getCG(ByRef oGraphicsNode As Object, _ Optional ByRef oCoordSet As Object = Nothing, _ Optional ByRef oOutDataSets As Object = Nothing) Dim oDoc As Document Set oDoc = ThisApplication.ActiveDocument Dim oDataOwner As Object Dim oGraphicsOwner As Object If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Or _ oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then Set oDataOwner = oDoc Set oGraphicsOwner = oDoc.ComponentDefinition ElseIf oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then If oDoc.ActiveSheet Is Nothing Then MsgBox ("The current document is a drawing. The code is supposed to draw client graphics on active sheet! But active sheet is null!") Exit Sub Else Set oDataOwner = oDoc.ActiveSheet Set oGraphicsOwner = oDoc.ActiveSheet End If End If On Error Resume Next Dim oDataSets As GraphicsDataSets Set oDataSets = oDataOwner.GraphicsDataSetsCollection("TestCG") If Not oDataSets Is Nothing Then oDataSets.Delete End If Dim oClientGraphics As Inventor.ClientGraphics Set oClientGraphics = oGraphicsOwner.ClientGraphicsCollection("TestCG") If Not oClientGraphics Is Nothing Then oClientGraphics.Delete End If Set oDataSets = oDataOwner.GraphicsDataSetsCollection.Add("TestCG") Set oOutDataSets = oDataSets Set oCoordSet = oDataSets.CreateCoordinateSet(oDataSets.Count + 1) Set oClientGraphics = oGraphicsOwner.ClientGraphicsCollection.Add("TestCG") Set oGraphicsNode = oClientGraphics.AddNode(oClientGraphics.Count + 1) End Sub 'getCG
This should work.
Inventor API Help contains overview and the set of code samples.
Cheers,
Hello,
The code works and is a good start. But I'll end up with some hours of programming before I get the end result.
I was hoping somebody had a quicker solution.
But I've seen that Autodesk has accepted this idea and made into a developmetn project. So I'm happy 🙂
You may develop this nice tool and publish it in the Exchange Apps Store!
🙂
http://apps.exchange.autodesk.com/INVNTOR/en/Home
>100 apps for Inventor today