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: 

Auto balloon macro for custom sketched symbols

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
djreesing
2448 Views, 14 Replies

Auto balloon macro for custom sketched symbols

Hello,

 

I'm trying to create a macro which will attach a custom sketched symbol with a leader to some specific parts in a view. By modifying some sample code I managed to create a macro which will attach the sketched symbol to the currently selected edge (see code below). However I would like to select the view and let the code cycle trough all the parts and check the filename or a custom iProperty. If the filename has a certain pattern or a specific custom iProperty exists it should add the sketched symbol. I don't really see how I should do this, I can get a reference to the selected view and as far as I can see I can use the referencedfiledescripter to open the assembly and cycle through the occurences. However I don't see how I can use this to add the sketched symbol to the occurence in the drawing view.

 

    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument

    ' Set a reference to the active sheet.
    Dim oActiveSheet As Sheet
    Set oActiveSheet = oDrawDoc.ActiveSheet
    
    ' Set a reference to the drawing curve segment.
    ' This assumes that a drwaing curve is selected.
    Dim oDrawingCurveSegment As DrawingCurveSegment
    Set oDrawingCurveSegment = oDrawDoc.SelectSet.item(1)

    ' Get the mid point of the selected curve
    ' assuming that the selection curve is linear
    Dim oStartPoint As Point2d
    Set oStartPoint = oDrawingCurveSegment.StartPoint

    ' Set a reference to the TransientGeometry object.
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry

    Dim oLeaderPoints As ObjectCollection
    Set oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection

    ' Create a couple of leader points.
    Call oLeaderPoints.Add(oTG.CreatePoint2d(oStartPoint.X + 2, oStartPoint.Y + 2))

    ' Add the GeometryIntent to the leader points collection.
    ' This is the geometry that the balloon will attach to.
    Dim oGeometryIntent As GeometryIntent
    Set oGeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurveSegment.Parent)
    Call oLeaderPoints.Add(oGeometryIntent)

    Call oActiveSheet.SketchedSymbols.AddWithLeader("Nozzle Tag", oLeaderPoints)

 

Any help would be appreciated.

 

Best regards, Daniël

14 REPLIES 14
Message 2 of 15
djreesing
in reply to: djreesing

Well I was too soon with posting my question. Already figured it out myself.

 

    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument

    ' Set a reference to the active sheet.
    Dim oActiveSheet As Sheet
    Set oActiveSheet = oDrawDoc.ActiveSheet
    
    ' Check if a drawing view is selected
    If oDrawDoc.SelectSet.Count = 0 Then
        Call MsgBox("Please select a drawing view.", vbInformation)
        Exit Sub
    ElseIf Not oDrawDoc.SelectSet.item(1).Type = kDrawingViewObject Then
        Call MsgBox("Current selection is not a drawing view.", vbInformation)
        Exit Sub
    End If

    ' Set a reference to the selected view
    Dim oView As DrawingView
    Set oView = oDrawDoc.SelectSet.item(1)
    
    Dim oDrawingCurve As DrawingCurve
    
    For Each oDrawingCurve In oView.DrawingCurves
        
        If oDrawingCurve.ModelGeometry.ContainingOccurrence.Name Like "TEST-NZ*" Then
            
            Dim oStartPoint As Point2d
            Set oStartPoint = oDrawingCurve.StartPoint
            
            If Not oStartPoint Is Nothing Then
            
                Dim oTG As TransientGeometry
                Set oTG = ThisApplication.TransientGeometry
                
                Dim oLeaderPoints As ObjectCollection
                Set oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection
                Call oLeaderPoints.Add(oTG.CreatePoint2d(oStartPoint.X + 2, oStartPoint.Y + 2))
                
                Dim oGeometryIntent As GeometryIntent
                Set oGeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve)
                Call oLeaderPoints.Add(oGeometryIntent)
                
                Call oActiveSheet.SketchedSymbols.AddWithLeader("Nozzle Tag", oLeaderPoints, , , , , True)
                
            End If
        End If
    
    Next oDrawingCurve

This will insert the sketched symbol for every drawingcurve of which the parent occurence name passes the check. I only need to add some kind of check if the occurence already has a symbol so it won't add multiple symbols to one occurence.

 

Cheers.

Message 3 of 15
jdkriek
in reply to: djreesing

....

 

Nevermind, I see you got it. 😉

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 4 of 15
karthikkumar_ml
in reply to: djreesing

Please help how to code this for attaching sketched symbol to the view (with 3 Prompted strings). Any help would save lot of time for me.

Message 5 of 15
djreesing
in reply to: karthikkumar_ml

Basically the same as my code above. You can specify the prompted entries in the 'oActiveSheet.SketchedSymbols.AddWithLeader' method.

 

When you have 3 prompted entries you need to dim a string like this:

Dim Prompts(2) as string

 

Set them like this:

Prompts(0) = "Text for entry 1"

Prompts(1) = "Text for entry 2"

Prompts(2) = "Text for entry 3"

 

Then you can use the string Prompts in the AddWIthLeader method.

 

See the Inventor programming help for more information on the AddWithLeader method if you don't understand.

 

Daniël

 

 

Message 6 of 15
ChristinaForest
in reply to: djreesing

i trying the 2 rule in this post but dont work for me 😞

 

leader error.PNG

Message 7 of 15
djreesing
in reply to: djreesing

Note that the above code is for a VBA macro, I'm not sure if it will work in an iLogic rule.

 

However make sure you change the code so the occurence name and sketched symbol name will match with what you have in your drawing.

 

Daniël

Message 8 of 15
ChristinaForest
in reply to: djreesing

Thanks for your reply Daniël!

 

Sorry for my horrible english, yes i have replace to my symbol name, but what is the occurence name?

sorry i'm not very good in vb or ilogic 😞

Message 9 of 15
djreesing
in reply to: djreesing

Look for this line:

 

If oDrawingCurve.ModelGeometry.ContainingOccurrence.Name Like "TEST-NZ*" Then

In my case the names of the parts in the assembly where like this: TEST-NZ01, TEST-NZ02 etc. The code would cycle through all parts and only attach a symbol if the part/occurence name starts with TEST-NZ

 

You can also delete this if..then structure so all parts wil get a symbol no matter what the name is.

 

Daniël

Message 10 of 15
ChristinaForest
in reply to: djreesing

i trying with and without extension file but the same error?

 

leader error2.PNGleader error22.PNG

Message 11 of 15
ChristinaForest
in reply to: djreesing

and when i delete de line with the occurence.name i have this error message?

 

leader error33.PNGleader error3.PNG

Message 12 of 15
djreesing
in reply to: ChristinaForest

As I already said, I'm not sure if this works in iLogic. So try it in a VBA macro to see if it works.

 

If you're unfamiliar with VBA, check the programming help in Inventor.

 

Daniël

Message 13 of 15

ok

Thanks for your help daniel, it's kind 🙂

 

not abble to work in vb but waiting for future help maybe 🙂

 

a good day for you!

Message 14 of 15
Yadow
in reply to: ChristinaForest

Hey guys.

 

Did you find any code to make it so that only one balloon was set for each "part/assembly" containing this name?

If anyone knows I would be happy to get a code for it :).

 

Best regards.

Message 15 of 15
Yadow
in reply to: Yadow

Is there any way to prevent more than one startpoint to be made for each Part/Assembly in the drawing view?

Thanks 

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

Post to forums  

Autodesk Design & Make Report