Automate Punch Bisector lines on inventor drawing

Automate Punch Bisector lines on inventor drawing

Anonymous
Not applicable
471 Views
8 Replies
Message 1 of 9

Automate Punch Bisector lines on inventor drawing

Anonymous
Not applicable

I am looking for a rule that automates placing bisector lines in an inventor drawing for sheet metal punches. I know there is a built in application for automated centerlines, but that doesn't seem to work for rectangular punches. Essentially I want a program that automatically places two center line bisectors on rectangular punches and center lines on circular punches. Is that possible? The end result I'm looking for is the screenshot below: 

 

CodyCZorn_0-1633008566963.png

 

0 Likes
472 Views
8 Replies
Replies (8)
Message 2 of 9

Michael.Navara
Advisor
Advisor

Why it is not possible to use automated centerlines for punch centers and modify newly created center marks. Extend them outside the punch area?

0 Likes
Message 3 of 9

Anonymous
Not applicable

ok, and how would I go about doing that?

0 Likes
Message 4 of 9

Michael.Navara
Advisor
Advisor

This is sample for first approach. You need to set appropriate xDiff and yDiff values for punchTool feature size

Sub Main()
    Dim drw As DrawingDocument = ThisDoc.Document
    Dim oSheet As Sheet = drw.ActiveSheet
    Dim drwView As DrawingView = oSheet.DrawingViews(1)


    Dim centerLineSettings As AutomatedCenterlineSettings
    drwView.GetAutomatedCenterlineSettings(centerLineSettings)
    centerLineSettings.ApplyToPunches = True

    Dim centermarks = drwView.SetAutomatedCenterlineSettings(centerLineSettings)

    For Each centermark As Centermark In centermarks.OfType(Of Centermark)
        Dim punchFeature = GetSourcePunchToolFeature(centermark)
        'You can use punchFeature to set xDif and yDif values
        'See punchFeature.iFeatureDefinition.iFeatureInputs for more details
        Dim xDif As Double = 1 '[cm]
        Dim yDif As Double = 1 '[cm]

        centermark.ExtensionPointOne = GetExtensionPoint(centermark.Position, centermark.ExtensionPointOneDirection, xDif, yDif)
        centermark.ExtensionPointTwo = GetExtensionPoint(centermark.Position, centermark.ExtensionPointTwoDirection, xDif, yDif)
        centermark.ExtensionPointThree = GetExtensionPoint(centermark.Position, centermark.ExtensionPointThreeDirection, xDif, yDif)
        centermark.ExtensionPointFour = GetExtensionPoint(centermark.Position, centermark.ExtensionPointFourDirection, xDif, yDif)

    Next

End Sub

Function GetExtensionPoint(extensionPoint As Point2d, pointDirection As UnitVector2d, xDif As Double, yDif As Double) As Point2d
    Dim coords() As Double = {}
    extensionPoint.GetPointData(coords)
    coords(0) += xDif * pointDirection.X
    coords(1) += yDif * pointDirection.Y
    extensionPoint.PutPointData(coords)
    Return extensionPoint
End Function

Function GetSourcePunchToolFeature(centermark As Centermark) As PunchToolFeature
    Dim intent As GeometryIntent = centermark.AttachedEntity
    Dim drwCurve As DrawingCurve = intent.Geometry
    Dim edge As Edge = drwCurve.ModelGeometry
    For Each face As Face In edge.Faces
        Dim createdByFeature As PartFeature = face.CreatedByFeature
        If createdByFeature.Type <> ObjectTypeEnum.kPunchToolFeatureObject Then Continue For
        Return createdByFeature
    Next
    Return Nothing
End Function
0 Likes
Message 5 of 9

Anonymous
Not applicable

I see your idea here, however i cannot seem to use the automate center lines command on rectangular punches only on round punches. Even without running the code, it will not allow me to use the center line function on rectangular punches. In order to get a centerline i have to select centerline bisector and click on all 4 edges. Is there a way to automate this?

0 Likes
Message 6 of 9

WCrihfield
Mentor
Mentor

Just food for thought here, but the Centermarks.Add method seems to have this type of scenario in mind if you read through the descriptions for its input variables.  The first input can be the GeometryIntent representing the DrawingCurve that represents an edge of the punch hole.  The second input you would likely want to be True, to show the extension lines.  Then the third input Boolean is to indicate that the Intent was the edge of a punch, and to use its origin as the location for the centermark.  (You might have to ensure the 'origin' in your punch is where you want it.)

 

oCM = oCMs.Add(oCurve, True, True)

 

Of course this is only one part of a fairly complex scenario.  You still need to find & identify the drawing curves that represent those punch holes in a way that you are able to process each punch hole individually, without processing it multiple times.  I'm sure there are likely multiple directions and strategies (rabbit holes) that could possibly be used to accomplish this task.  You could assign names to the faces/edges in the part to make it easier to find them from the drawing.  You could loop through the iFeatures in the model, then get the specific set of drawing curves that represent each specific iFeature in the model within the drawing view by using the DrawingView.DrawingCurves(iFeature), then only use one of the drawing curves from that collection to generate the centermark from for each iFeature.  Or you could probably work your way down from the top, doing a 'deep dive' on each drawing curve, then adding it to a collection when it belongs to one of the iFeatures, so you only process one curve from each feature, but this path seems less efficient.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 9

WCrihfield
Mentor
Mentor

If the origin point of your punch type iFeature is at the center of that rectangle that may make this task easier.  If this is the case, then something fairly simple like this might work for you (in theory).

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
	iFeats = oModel.ComponentDefinition.Features.iFeatures
	For Each iFeat As Inventor.iFeature In iFeats
		If iFeat.iFeatureDefinition.IsPunchTool Then
			oCurves = oView.DrawingCurves(iFeat)
			oCurve = oCurves.Item(1)
			oIntent = oSheet.CreateGeometryIntent(oCurve)
			oCM = oCMs.Add(oIntent, True, True)
		End If
	Next
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 9

WCrihfield
Mentor
Mentor

I just created another test scenario using extruded rectangular cuts in a part, instead of rectangular punch iFeatures (as a quick & simple test subject).  I was able to add the bisecting center lines to a the rectangular cutout in the drawing view fairly easily using some of what I mentioned earlier.

Dim oDDoc As DrawingDocument = ThisDoc.Document
oSheet = oDDoc.ActiveSheet
oView = oSheet.DrawingViews.Item(1)
oCLs = oSheet.Centerlines
Dim oModel As PartDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
oCut1 = oModel.ComponentDefinition.Features.ExtrudeFeatures.Item("Cut 1")
oCurves = oView.DrawingCurves(oCut1)

oIntent1 = oSheet.CreateGeometryIntent(oCurves.Item(1))
oIntent3 = oSheet.CreateGeometryIntent(oCurves.Item(3))
oCL1 = oCLs.AddBisector(oIntent1, oIntent3)

oIntent2 = oSheet.CreateGeometryIntent(oCurves.Item(2))
oIntent4 = oSheet.CreateGeometryIntent(oCurves.Item(4))
oCL2 = oCLs.AddBisector(oIntent2, oIntent4)

The bit of code that creates the bisecting lines could be put into a separate Sub, if needed.  Of course this looks so simple because we know we have a view of a simple fully/mostly flat part, and we know ahead of time that all the cutouts will be rectangular, and facing us, so we know each cutout (or punch hole) will have 4 lines, with opposing lines being parallel with each other.  And we know from experience that the lines making up a rectangle in these types of situations are always (usually) sequential (1 & 3 are parallel while 2 & 4 are parallel).  If you had a loop of the features, you could run the reference Sub to create its bisecting lines once per feature.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 9

Anonymous
Not applicable

Im not exactly sure wheat you mean by the origin point of your punch type iFeature is at the center of that rectangle. i want the bisector lines to go through the center of the rectangular punch. Essential i want to automate turning this drawing:

CodyCZorn_0-1633370987546.png

 

Into this drawing:

CodyCZorn_1-1633371036279.png

 

For as many punches that exist in the entire drawing.

 

 

0 Likes