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: 

Trying to place Leader notes but somehow its not getting placed on the view I want

7 REPLIES 7
Reply
Message 1 of 8
sohaib.as01
330 Views, 7 Replies

Trying to place Leader notes but somehow its not getting placed on the view I want

Hello guys,

So I am banging my head against the wall for quite some hours but still dont understand whats wrong with my code.

I have three views my drawing, names are:
ISO
LEFT_END
FRONT.

I want to place leader note on both ISO and LEFT_END view. 

The leader note on ISO view is getting placed correctly, so I copied the same code into new ilogic rule and when after I did the necessary changes and tried to run the code, its placing it on the ISO view instead of LEFT_END view. I domt seem to understand the whats the problem here is.

I would greatly appreciate the help.

Here is my code:

 

oSheet = ThisDoc.Document.ActiveSheet
 
 
Dim LNote As LeaderNote
For Each LNote In oSheet.DrawingNotes
If LNote.AttributeSets.NameIsUsed("iLogic_Created") = True Then
LNote.Delete
End If
Next
 
Dim oDrawingDocument As DrawingDocument
oDrawingDocument = ThisDoc.Document
Dim oDoc As Document
 
Dim oLeaderWP As WorkPoint
Dim oLeaderWPP As WorkPointProxy
Dim cm As Centermark
Dim oCmLeader As Centermark
Dim sText As String
 
Dim oOccs As ComponentOccurrences
Dim oOcc As ComponentOccurrence
 
Dim oGeom As GeometryIntent
Dim oPlacementPoint As Point2d
Dim oObjCollect As ObjectCollection
Dim oLeaderNote As LeaderNote
 
 
 
AssyName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
Dim paramSheetMetal As Boolean
paramSheetMetal = Parameter(AssyName, "SHEET_METAL")
 
View_LEFT_END = ActiveSheet.View("LEFT_END").View
 
If Parameter(AssyName, "End_Stop") = "Yes" Then
oAssyDoc1 = ActiveSheet.View("LEFT_END").ModelDocument
For Each oDoc In oAssyDoc1.AllReferencedDocuments
If oDoc.DisplayName = "ENDSTOP-01" Then
oEndStopDoc = oDoc
End If
Next
 
oLeaderWP = oEndStopDoc.ComponentDefinition.WorkPoints.Item("LeaderWP")
oOccs = oAssyDoc1.ComponentDefinition.Occurrences
 
For Each oOcc In oOccs
If oOcc.Name = "ENDSTOP-01:1" Then
oOcc.CreateGeometryProxy(oLeaderWP, oLeaderWPP)
View_LEFT_END.SetIncludeStatus(oLeaderWPP,True)
 
For Each cm In oSheet.Centermarks
            If cm.Attached Then
                If cm.AttachedEntity Is oLeaderWPP Then
                    oCmLeader = cm
                End If
            End If
        Next
End If
Next
oGeom = oSheet.CreateGeometryIntent(oCmLeader)
oPlacementPoint = ThisServer.TransientGeometry.CreatePoint2d(oCmLeader.Position.X - 1, oCmLeader.Position.Y + 1)
oObjCollect = ThisServer.TransientObjects.CreateObjectCollection
oObjCollect.Add(oPlacementPoint)
oObjCollect.Add(oGeom)
sText = "End Stop"
oLeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oObjCollect, sText)
oCmLeader.Visible = True
oLeaderNote.AttributeSets.Add("iLogic_Created")
 
End If
oSheet = ThisDoc.Document.ActiveSheet
 
 
Dim LNote As LeaderNote
For Each LNote In oSheet.DrawingNotes
If LNote.AttributeSets.NameIsUsed("iLogic_Created") = True Then
LNote.Delete
End If
Next
 
Dim oDrawingDocument As DrawingDocument
oDrawingDocument = ThisDoc.Document
Dim oDoc As Document
 
Dim oLeaderWP As WorkPoint
Dim oLeaderWPP As WorkPointProxy
Dim cm As Centermark
Dim oCmLeader As Centermark
Dim sText As String
 
Dim oOccs As ComponentOccurrences
Dim oOcc As ComponentOccurrence
 
Dim oGeom As GeometryIntent
Dim oPlacementPoint As Point2d
Dim oObjCollect As ObjectCollection
Dim oLeaderNote As LeaderNote
 
 
 
AssyName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
Dim paramSheetMetal As Boolean
paramSheetMetal = Parameter(AssyName, "SHEET_METAL")
 
View_LEFT_END = ActiveSheet.View("LEFT_END").View
 
If Parameter(AssyName, "End_Stop") = "Yes" Then
oAssyDoc1 = ActiveSheet.View("LEFT_END").ModelDocument
For Each oDoc In oAssyDoc1.AllReferencedDocuments
If oDoc.DisplayName = "ENDSTOP-01" Then
oEndStopDoc = oDoc
End If
Next
 
oLeaderWP = oEndStopDoc.ComponentDefinition.WorkPoints.Item("LeaderWP")
oOccs = oAssyDoc1.ComponentDefinition.Occurrences
 
For Each oOcc In oOccs
If oOcc.Name = "ENDSTOP-01:1" Then
oOcc.CreateGeometryProxy(oLeaderWP, oLeaderWPP)
View_LEFT_END.SetIncludeStatus(oLeaderWPP,True)
 
For Each cm In oSheet.Centermarks
            If cm.Attached Then
                If cm.AttachedEntity Is oLeaderWPP Then
                    oCmLeader = cm
                End If
            End If
        Next
End If
Next
oGeom = oSheet.CreateGeometryIntent(oCmLeader)
oPlacementPoint = ThisServer.TransientGeometry.CreatePoint2d(oCmLeader.Position.X - 1, oCmLeader.Position.Y + 1)
oObjCollect = ThisServer.TransientObjects.CreateObjectCollection
oObjCollect.Add(oPlacementPoint)
oObjCollect.Add(oGeom)
sText = "End Stop"
oLeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oObjCollect, sText)
oCmLeader.Visible = True
oLeaderNote.AttributeSets.Add("iLogic_Created")
 
End If
 

 

Labels (1)
7 REPLIES 7
Message 2 of 8
A.Acheson
in reply to: sohaib.as01

Hi @sohaib.as01 

 

I formatted your code a little as it was hard to figure out what was happening where, it looked like you might have double posted the code. I would also suggest you use the built in tools to paste the code in order to keep the formatting.

AAcheson_0-1688416843388.png

 

This one is very hard to test without the file set mainly because of all the interconnected parameters. Does each view your targeting have the same model document? I didn't see two views referenced in this code so maybe check if the same code can be used for each view in order to recycle the code rather than duplicate it. 

Dim oSheet As Sheet = ThisDoc.Document.ActiveSheet
 
Dim LNote As LeaderNote
For Each LNote In oSheet.DrawingNotes
	If LNote.AttributeSets.NameIsUsed("iLogic_Created") = True Then
		LNote.Delete
	End If
Next
 
Dim oDrawingDocument As DrawingDocument
oDrawingDocument = ThisDoc.Document

Dim oDoc As Document
Dim oLeaderWP As WorkPoint
Dim oLeaderWPP As WorkPointProxy
Dim cm As Centermark
Dim oCmLeader As Centermark
Dim sText As String
Dim oOccs As ComponentOccurrences
Dim oOcc As ComponentOccurrence
Dim oGeom As GeometryIntent
Dim oPlacementPoint As Point2d
Dim oObjCollect As ObjectCollection
Dim oLeaderNote As LeaderNote

 
Dim AssyName As String  = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
Dim paramSheetMetal As Boolean
paramSheetMetal = Parameter(AssyName, "SHEET_METAL")

View_LEFT_END = ActiveSheet.View("LEFT_END").View
 
If Parameter(AssyName, "End_Stop") = "Yes" Then
	Dim oAssyDoc1 As AssemblyDocument = ActiveSheet.View("LEFT_END").ModelDocument
	
	For Each oDoc In oAssyDoc1.AllReferencedDocuments
		If oDoc.DisplayName = "ENDSTOP-01" Then
			oLeaderWP = oDoc.ComponentDefinition.WorkPoints.Item("LeaderWP")
		End If
	Next
 
	oOccs = oAssyDoc1.ComponentDefinition.Occurrences
	 
	For Each oOcc In oOccs
		If oOcc.Name = "ENDSTOP-01:1" Then
			oOcc.CreateGeometryProxy(oLeaderWP, oLeaderWPP)
			View_LEFT_END.SetIncludeStatus(oLeaderWPP,True)
			 
			For Each cm In oSheet.Centermarks
				If cm.Attached Then
					If cm.AttachedEntity Is oLeaderWPP Then
						oCmLeader = cm
					End If
				End If
			Next
		End If
	Next
	
	oGeom = oSheet.CreateGeometryIntent(oCmLeader)
	oPlacementPoint = ThisServer.TransientGeometry.CreatePoint2d(oCmLeader.Position.X - 1, oCmLeader.Position.Y + 1)
	oObjCollect = ThisServer.TransientObjects.CreateObjectCollection
	oObjCollect.Add(oPlacementPoint)
	oObjCollect.Add(oGeom)
	sText = "End Stop"
	oLeaderNote = oSheet.DrawingNotes.LeaderNotes.Add(oObjCollect, sText)
	oCmLeader.Visible = True
	oLeaderNote.AttributeSets.Add("iLogic_Created")
 
End If

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 8
sohaib.as01
in reply to: A.Acheson

Hey @A.Acheson thanks for the reply.

Sorry for posting the code as it is, I didnt know how to format the code using tools, i will definitely follow this from now on.

So the code that you posted, i believe there is nothing changed i what I posted except formatting cause it's behaving the same way. Let me clarify more as to whats happening.

1. I am supposed to place same leader notes on two different drawing views, which are names as ISO and LEFT_END
2. Now the code is working fine for the ISO view

3. So I copied the same code into different ilogic rule and did the necessary changes to make the variable View_LEFT_END to get the LEFT_END view where previously it was getting ISO view.
4. Now even after doing that, the leader note is getting placed on the ISO view, I am double sure that the view is pointing to the LEFT_END view and not the ISO view. 

5. One interesting thing to note here is that, if I delete the ISO view,and then run the rule, only then the leader note gets placed on the LEFT_END view. WHY??

6. So i am thinking may be the problem is in this bit:

 

oOccs = oAssyDoc1.ComponentDefinition.Occurrences
	 
	For Each oOcc In oOccs
		If oOcc.Name = "ENDSTOP-01:1" Then
			oOcc.CreateGeometryProxy(oLeaderWP, oLeaderWPP)
			View_LEFT_END.SetIncludeStatus(oLeaderWPP,True)
			 
			For Each cm In oSheet.Centermarks
				If cm.Attached Then
					If cm.AttachedEntity Is oLeaderWPP Then
						oCmLeader = cm
					End If
				End If
			Next
		End If
	Next

where it is looping through all the centermarks on the sheet but then again, it is being forced to loop oOccs in AssyDoc1, so shouldnt it point towards the LEFT_END view?

Message 4 of 8
A.Acheson
in reply to: sohaib.as01

Hi @sohaib.as01 

I am thinking the issue here is that your getting an occurrence but you have to note that this is repeated multiple times for each view. You need to connect the occurrence to that of the view you want to target. From this post you here you likely have this solved. If you haven't let us know. 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 8
sohaib.as01
in reply to: A.Acheson

@A.Acheson  you are right the occurence is of course repeated in multiple views but arent the following lines of code making sure that the occurence is referred to that specific view I am trying to place the leader note on?

line 34:

 

Dim oAssyDoc1 As AssemblyDocument = ActiveSheet.View("LEFT_END").ModelDocument

line 42:

oOccs = oAssyDoc1.ComponentDefinition.Occurrences

and when I loop through the occurences to reach the specific centermark:

For Each oOcc In oOccs
		If oOcc.Name = "ENDSTOP-01:1" Then
			oOcc.CreateGeometryProxy(oLeaderWP, oLeaderWPP)
			View_LEFT_END.SetIncludeStatus(oLeaderWPP,True)
			 
			For Each cm In oSheet.Centermarks
				If cm.Attached Then
					If cm.AttachedEntity Is oLeaderWPP Then
						oCmLeader = cm
					End If
				End If
			Next
		End If
	Next

 would it help if i posted the whole file package here? would you go through it to verify?

Message 6 of 8
A.Acheson
in reply to: sohaib.as01

Hi @sohaib.as01 

This post here checks the view to the centermark on the sheet. 

 

In your current view you will something along the lines of this. 

Dim view As Inventor.DrawingView = c.AttachedEntity.Geometry.Parent
	If Not view.Name = DesiredViewName Then Continue For

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 7 of 8
sohaib.as01
in reply to: A.Acheson

Nope, this isn't working out. Its not storing any kind of centermarks at all.

Message 8 of 8
J-Camper
in reply to: sohaib.as01

@sohaib.as01,

 

My first thought was also that you might be finding the centermark from another view, whose occurrence is the same.  Even though you say it is not, try this bit of code replacement that will highlight and pause to show you the centermark found:

 

For Each oOcc In oOccs
		If oOcc.Name = "ENDSTOP-01:1" Then
			oOcc.CreateGeometryProxy(oLeaderWP, oLeaderWPP)
			View_LEFT_END.SetIncludeStatus(oLeaderWPP,True)
			 
			For Each cm In oSheet.Centermarks
				If cm.Attached Then
					If cm.AttachedEntity Is oLeaderWPP Then
						oCmLeader = cm
						Dim selectThis As HighlightSet = ThisApplication.ActiveDocument.CreateHighlightSet
						selectThis.AddItem(cm)
						MessageBox.Show("This is the centermark found", "Pause")
						selectThis.Clear
					End If
				End If
			Next
		End If
	Next

 

If that is not the issue, my second thought is the object collection "oObjCollect".  If you are moving from the first view to the second view without re-creating or clearing the object collection then it may contain the previous geometry intent and position point in the collection.  The attachment geometry is the first in the collection, so it would still connect to the first view.  Do you re-create or clear the object collection between views?

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report