Turn on Punch Centers in Drawing

Turn on Punch Centers in Drawing

cwellborn4YTEL
Observer Observer
447 Views
3 Replies
Message 1 of 4

Turn on Punch Centers in Drawing

cwellborn4YTEL
Observer
Observer

I have run into a problem creating some code in the VBA editor.

To sum up the problem, I want to create code that turns on the “Punch Centers” in a drawing view on a .dwg:

cwellborn4YTEL_0-1712856765984.png

 

For example, on a .dwg that contains 1 sheet and 1 view, following the path:

ThisApplication.ActiveDocument.Sheets.Item(1).DrawingViews.Item(1)

 

This path will give you options to display every other feature in the drawing, except punch centers:

 

cwellborn4YTEL_1-1712856765985.png

 

 

Is there an option in Inventor that has this listed? Or is there another way to turn on punch centers?

 

I am running Inventor 2022.

0 Likes
448 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @cwellborn4YTEL.  What you are looking for is not a direct 'Property' of the DrawingView object that you would be able to see in that list in VBA.  What you are looking for is the AutomatedCenterlineSettings object.  This is normally located within each DrawingDocument, under its DrawingSettings (DrawingSettings.AutomatedCenterlineSettings ).  The DrawingView object has two 'Methods' for working with the settings in this object.

DrawingView.GetAutomatedCenterlineSettings 

DrawingView.SetAutomatedCenterlineSettings 

When you use the 'Set' method, it will apply those to settings at that time, and return the entities it created.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

cwellborn4YTEL
Observer
Observer

Good Afternoon @WCrihfield, Thank you for the quick response. I apologize for the delay. I wasn't able to implement what you suggested until yesterday. I got the punch marks to turn on for the round punches. Is there a way to turn the punch centers for non-round punch features?

cwellborn4YTEL_0-1713375039205.png

 

Here is where I implement your comment in the code:

cwellborn4YTEL_1-1713375099760.png

 



0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Hi @cwellborn4YTEL.  That is a good question.  Unfortunately, as far as I know, there is no simple or easy way to do that.  I responded to a similar forum post once or twice before about a similar request, and do not recall where that was, or I would provide a link to the old discussion(s) here.  Anyways, I kept a test part & drawing for that task, which seemed to be working OK for me.  I will post the iLogic code for that task below.  However, this is only for that specific situation where the model is a sheet metal part, and those features were created by real punch tool features.  This does not include the 'AutomatedCenterlineSettings' stuff.  It is pretty intense, so it may add a few more Centermarks than may be needed / wanted.  It can be further developed / refined though, as needed.

Sub Main
	Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then Return
	Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
	Dim oViews As DrawingViews = oSheet.DrawingViews
	If oViews.Count = 0 Then Return
	Dim oAllPunchCenterMarksCreated As New List(Of Inventor.Centermark)
	Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oDDoc, "PunchCenterPoints")
	For Each oView As DrawingView In oViews
		Dim oListOfCentermarksCreated As New List(Of Inventor.Centermark)
		Try
			oListOfCentermarksCreated = AddCentermarksToPunchToolHoles(oView)
		Catch
			Logger.Error("AddCentermarksToPunchToolHoles Function encountered an Error.")
			oTrans.Abort
		End Try
		If oListOfCentermarksCreated.Count > 0 Then
			oAllPunchCenterMarksCreated.AddRange(oListOfCentermarksCreated)
		End If
	Next
	oTrans.End
	Dim oHLS As HighlightSet = oDDoc.CreateHighlightSet
	If oAllPunchCenterMarksCreated.Count > 0 Then
		For Each oCM In oAllPunchCenterMarksCreated
			oHLS.AddItem(oCM)
		Next 'oCM
	End If
	MsgBox("Review all Centermarks created for PunchToolFeatures.", vbInformation, "iLogic")
	oHLS.Clear
End Sub

Function AddCentermarksToPunchToolHoles(oDView As DrawingView) As List(Of Inventor.Centermark)
	If oDView.ReferencedDocumentDescriptor.ReferencedDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
		Return Nothing
	End If
	Dim oPDoc As PartDocument = oDView.ReferencedDocumentDescriptor.ReferencedDocument
	If Not TypeOf oPDoc.ComponentDefinition Is SheetMetalComponentDefinition Then Return Nothing
	Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
	Dim oSMFeats As SheetMetalFeatures = oSMDef.Features
	Dim oPunchToolFeats As PunchToolFeatures = oSMFeats.PunchToolFeatures
	If oPunchToolFeats.Count = 0 Then Return Nothing
	Dim oSheet As Inventor.Sheet = oDView.Parent
	Dim oCMs As Inventor.Centermarks = oSheet.Centermarks
	Dim oList As New List(Of Inventor.Centermark)
	For Each oPunch As PunchToolFeature In oPunchToolFeats
		Dim oCurves As DrawingCurvesEnumerator
		Try : oCurves = oDView.DrawingCurves(oPunch) : Catch : End Try
		If oCurves Is Nothing OrElse oCurves.Count = 0 Then Continue For
		For Each oDCurve As DrawingCurve In oCurves
			Dim oIntent As GeometryIntent = oSheet.CreateGeometryIntent(oDCurve)
			Dim oCM As Centermark = Nothing
			Try
				oCM = oCMs.Add(oIntent, True, True)
			Catch
				Continue For 'skip to next oDCurve
			End Try
			If oList.Count = 0 Then
				oList.Add(oCM) 'if first Centermark, add it to the List
			Else 'if other Centermarks exist, make sure they are not in same position, if so, delete it
				Dim bFound As Boolean = False
				For Each oCMk In oList
					Try : If oCMk.Position.IsEqualTo(oCM.Position, 0.001) Then bFound = True
					Catch : End Try
					Try : If bFound Then : oCM.Delete : End If : Catch : End Try
				Next 'oCMk
				Try : If Not bFound Then : oList.Add(oCM) : End If : Catch : End Try
			End If
		Next 'oDCurve
	Next 'oPunch
	Return oList
End Function

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes