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
Solved! Go to Solution.
Solved by djreesing. Go to Solution.
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.
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.
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
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
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 😞
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
and when i delete de line with the occurence.name i have this error message?
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
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!
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.