Automate adding centerline bisectors to drawing

Automate adding centerline bisectors to drawing

Anonymous
Not applicable
1,546 Views
7 Replies
Message 1 of 8

Automate adding centerline bisectors to drawing

Anonymous
Not applicable

Im looking for an inventor rule that will automate the process for adding centerline bisectors to square punches on an inventor drawing. Essential I'm looking for a rule to automate turning a drawing from this: 

CodyCZorn_0-1633454018838.png

To this:

CodyCZorn_1-1633454029622.png

Is this possible? Thanks!

0 Likes
Accepted solutions (1)
1,547 Views
7 Replies
Replies (7)
Message 2 of 8

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Anonymous.  After a lot of work creating the models and punches to be able to fully test this idea, I think I finally have something that should work for you, because it worked for me in the same scenario. I created a sheet metal part that looks just like yours.  Created a rectangular sheet metal punch iFeature to use for this example.  Created a sketch of center points for the punch tool to use as centers.  Used the Punch tool to add the single punch feature to the model tree that represented a pattern of punched holes (one for each center mark in the sketch).  Then created a drawing of this part.  Then created this iLogic rule to tackle this task for you.  I'm using the same technique I mentioned in the other post (Centermarks.Add()), but added some additional code to help manage them, and avoid duplicates.  Here's the code that I ended up with, that created the perfect looking center marks on each rectangular punch hole in the view, just as I was expecting.

Sub Main
	Dim oDDoc As DrawingDocument = ThisDoc.Document
	oSheet = oDDoc.ActiveSheet
	oView = oSheet.DrawingViews.Item(1)
	oCLs = oSheet.Centerlines
	oCMs = oSheet.Centermarks

	Dim oModel As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
	oPunch1 = oModel.ComponentDefinition.Features.Item("iFeature1:1")
	oCurves = oView.DrawingCurves(oPunch1)
	Dim oList As New List(Of Inventor.Centermark)
	For Each oDCurve As DrawingCurve In oCurves
		oIntent = oSheet.CreateGeometryIntent(oDCurve)
		oCM = oCMs.Add(oIntent, True, True)
		If oList.Count = 0 Then
			oList.Add(oCM)
		Else
			Dim oFound As Boolean = False
			For Each oCMk As Centermark In oList
				If oCMk.Position.IsEqualTo(oCM.Position) Then
					oFound = True
					oCM.Delete
				End If
			Next
			If Not oFound Then oList.Add(oCM)
		End If
	Next
End Sub

Whew... 🙂

 

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

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 8

Anonymous
Not applicable

Thank you for taking the time to help me on this! I really appreciate it. However, when I run this rule im receiving the following error:

 

Error in rule: Auto Centerline, in document: LAL6I36MM00H00

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

Is there something i need to do besides just creating a rule with your code and running it on a drawing? Thanks!

0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor

Well, I did run into an interesting situation when creating this.  For some reason, this local rule in the drawing wasn't finding any 'iFeature' objects in the model, even though I used the 'Punch Tool' in the Sheet Metal tools of the model to create the feature, and the feature was named "iFeature1:1".   I later remembered that those PunchTools are a bit harder to find, because you first have to define then dig into the 'SheetMetalComponentDefinition' object, then define and dig into the 'SheetMetalFeatures' object below that to find them.  So, instead I just specified the feature by its name, which worked for my test at the time.

 

There are definitely some things that can be done to make this rule more robust.  I updated my rule code a bit to help eliminate some potential error prone areas.  Now it also loops through all views, and will also add the side profile centerlines, and add centerpoints in the ISO view (although not angled/rotated), but you can easily eliminate that loop to just process a single view if needed.  I also added a Transaction in there to help control the length of the Undo list, but it doesn't appear to be working as expected yet.

Here's my updated rule code as it is now:

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this rule to work. Exiting.",vbCritical, "iLogic")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	oSheet = oDDoc.ActiveSheet
	'Dim oView As DrawingView = oDDoc.SelectSet.Item(1)
	Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oDDoc, "PunchCenterPoints")
	For Each oView As DrawingView In oSheet.DrawingViews
		AddCentermarksToPunchToolHoles(oView)
	Next
	oTrans.End
End Sub

Sub AddCentermarksToPunchToolHoles(oDView As DrawingView)
	If oDView.ReferencedDocumentDescriptor.ReferencedDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
		Exit Sub
	End If
	Dim oPDoc As PartDocument = oDView.ReferencedDocumentDescriptor.ReferencedDocument
	If Not TypeOf oPDoc.ComponentDefinition Is SheetMetalComponentDefinition Then Exit Sub
	Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
	Dim oSMFeats As SheetMetalFeatures = oSMDef.Features
	If oSMFeats.PunchToolFeatures.Count = 0 Then Exit Sub 
	For Each oPunch As PunchToolFeature In oSMFeats.PunchToolFeatures
		Dim oCurves As DrawingCurvesEnumerator
		Try
			oCurves = oDView.DrawingCurves(oPunch)
		Catch
		End Try
		If IsNothing(oCurves) Then Continue For
		If oCurves.Count = 0 Then Continue For
		Dim oList As New List(Of Inventor.Centermark)
		For Each oDCurve As DrawingCurve In oCurves
			oIntent = oDView.Parent.CreateGeometryIntent(oDCurve)
			Dim oCM As Centermark
			Try
				oCM = oDView.Parent.Centermarks.Add(oIntent, True, True)
			Catch
				Continue For
			End Try
			If oList.Count = 0 Then
				oList.Add(oCM)
			Else
				Dim oFound As Boolean = False
				For Each oCMk As Centermark In oList
					If oCMk.Position.IsEqualTo(oCM.Position) Then
						oFound = True
						oCM.Delete
					End If
				Next
				If Not oFound Then oList.Add(oCM)
			End If
		Next
	Next
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 8

Anonymous
Not applicable

Hello, with your new rule I am no longer receiving an error, however no centerline are appearing on the drawing. I am not sure why the centerlines would show up on your drawing but not mine? 

0 Likes
Message 6 of 8

WCrihfield
Mentor
Mentor

I will attach the files I was working with, but they were created in Inventor Pro 2022.1.1, so if you're using an earlier version, they may not work for you.  The attached ZIP file contains the Part (.ipt), the Drawing (.idw), and the Punch Tool (.ide).  You would need to put that punch tool into your Punches folder, inside your Catalog folder, so that when you use the Punch tool, it will be able to easily find it.  But there's honestly not really anything too special about it.

WCrihfield_0-1633541709160.png 

WCrihfield_1-1633541770084.png 

WCrihfield_2-1633541855412.png

 

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 8

Anonymous
Not applicable

Yea i am running inventor 2018, that must be the issue here

0 Likes
Message 8 of 8

WCrihfield
Mentor
Mentor

Maybe.  It can be hard to tell, because they don't put revision notes in the online help pages that would tell you when abilities of methods or properties have changed, just the Inventor version the main method or property was first added.  You would almost have to search through all the 'What's New in XXXX' version pages.

For example:

DrawingView.DrawingCurves()  - version 11

Centermarks.Add() - 2009

Point2d.IsEqualTo() - 2008...etc.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes