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:
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.
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
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?
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.
@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?
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
Nope, this isn't working out. Its not storing any kind of centermarks at all.
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.