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: 

Is there a way to loop through centermarks on a specfic view on a sheet?

9 REPLIES 9
Reply
Message 1 of 10
sohaib.as01
420 Views, 9 Replies

Is there a way to loop through centermarks on a specfic view on a sheet?

So I am trying to write a code where I dont have to lopp through all the centermakrs placed on the view in a sheet, i just want to target one specific view with specific name and loop through all the centermarks of that view only. Is that possible?

9 REPLIES 9
Message 2 of 10
FINET_Laurent
in reply to: sohaib.as01

Hi @sohaib.as01 ,

 

You can indeed get to the parent view like this :

Dim Doc As Inventor.DrawingDocument
Doc = ThisApplication.ActiveDocument

Dim c As Inventor.Centermark
c = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCentermarkFilter, "")
	
Dim view As Inventor.DrawingView = c.AttachedEntity.Geometry.Parent

You could maybe then check the centermark parent view name with the wanted view name.

 Can you manage your code with this information ?

 

Edit : You can go from centermark to view like shown above, but I don't know if you can go from view to centermark.

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 3 of 10
sohaib.as01
in reply to: FINET_Laurent

Hey @FINET_Laurent thanks for the reply.
Ummh, i don't think that will be useful for me, what I want to do is, loop through all the centermarks and do something in that loop on a specfic view, so I am thinking the workflow would be:
1. Defining a specfic oView
2. Somehow writing a code which will lop through all the centermarks of this view

3. Do somethinmg i want to do in that for loop with a specfic centermark
4. Save that centermark in another cenntermark variable

5. Exit the loop

Makes sense??

Message 4 of 10
FINET_Laurent
in reply to: sohaib.as01

Hi @sohaib.as01 ,

 

As I mentionned I don't think you can execute the said workflow.

How I would go about it is this way : 

 

1. Create a collection

2. Check each centermarks to see if the parent view is the desired view. If yes, add the centermark to the collection, if no then skip the centermark.

3. Once the collection is complete, do your stuff.

 

Here is an exemple :

 

 

Dim Doc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
Dim s As Inventor.Sheet = Doc.ActiveSheet

Dim DesiredViewName As String = "VUE114"
Dim CntrMarks As Inventor.ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

For Each c As Inventor.Centermark In s.Centermarks
	Dim view As Inventor.DrawingView = c.AttachedEntity.Geometry.Parent
	If Not view.Name = DesiredViewName Then Continue For
	CntrMarks.Add(c)
		
Next

For Each c As Inventor.Centermark In CntrMarks
	'Do something
	
Next

 

 

This will create a collection with all the centermarks placed on the view names "VUE114", then loop throuugh this collection. Does this suits your need ? 

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 5 of 10
sohaib.as01
in reply to: FINET_Laurent

Hi @FINET_Laurent thanks for the elaboration. I think it will work this way.

Just a small confusion now,

On line 9, shouldnt it be:

 

If ViewCheck.Name = DesiredViewName Then
       CntrMarks.Add(c)
End If

 

instead of what you wrote? Or are they both the same thing?

Message 6 of 10
FINET_Laurent
in reply to: sohaib.as01

Hi @sohaib.as01 

 

It's called a guard clause. It indeed does the same job. 😃 

It just prevent abusive nesting. The code is then easier to read, etc.. 

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Tags (1)
Message 7 of 10
sohaib.as01
in reply to: FINET_Laurent

Yayy thank you so very much @FINET_Laurent .

Would you be so kind to go through this code of mine and see why is it giving error: "Public member 'Geometry' on type 'WorkPoint' not found."? 

I am trying to see if the centermark we have found from the CntrMrks object collection is asssociated with a specific WorkPointProxy, if yes then it will save that centermark and then use the centermark to place a leader note. But somehow its not happenig. Can you please do me a huge favor and see why not?
here is the full code:

line 48 to 78 will be of your interest, the error is occurring at line 78

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
		
		Dim CntrMarks As Inventor.ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
		For Each c As Centermark In oSheet.Centermarks
			Dim ViewCheck As DrawingView = c.AttachedEntity.Geometry.Parent
			If ViewCheck.Name = View_LEFT_END Then
				CntrMarks.Add(c)
			End If
		Next
		For Each cm In CntrMarks
            If cm.Attached = True Then
                If cm.AttachedEntity Is oLeaderWPP Then
                    oCmLeader = cm
                End If
            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

 

 

Message 8 of 10
sohaib.as01
in reply to: FINET_Laurent

Actually, as it turns out, i found out the code is just not going past line 7, it is just not doing the work at line 8 and just exiting the loop, hence nothing is being saved in CntrMrks object collection. 

@FINET_Laurent can you please help me out with a workaround?

Dim Doc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
Dim s As Inventor.Sheet = Doc.ActiveSheet

Dim DesiredViewName As String = "VUE114"
Dim CntrMarks As Inventor.ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

For Each c As Inventor.Centermark In s.Centermarks
	Dim view As Inventor.DrawingView = c.AttachedEntity.Geometry.Parent
	If Not view.Name = DesiredViewName Then Continue For
	CntrMarks.Add(c)
		
Next

For Each c As Inventor.Centermark In CntrMarks
	'Do something
	
Next

 

Message 9 of 10
FINET_Laurent
in reply to: sohaib.as01

Hi @sohaib.as01

 

What you are declaring here is a view object :

 

View_LEFT_END = ActiveSheet.View("LEFT_END").View

 

 

And later you are comparing it to a string.. : 

 

If ViewCheck.Name = View_LEFT_END Then

 

 ViewCheck.Name is a string and View_LEFT_END is a view. Comparing both obviously won't work.

 

I guess you would have to do this, thus comparing two strings.. : 

If ViewCheck.Name = View_LEFT_END.Name Then

 

Kind regards,

FINET L. 

 

 

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 10 of 10
sohaib.as01
in reply to: FINET_Laurent

@FINET_Laurent 
Yup I realized that as soon as i posted the reply here, and did exactly what you said, but to no effect. 

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report