How to set start and end points to automate break feature in drawing

How to set start and end points to automate break feature in drawing

Anonymous
Not applicable
1,945 Views
9 Replies
Message 1 of 10

How to set start and end points to automate break feature in drawing

Anonymous
Not applicable

Hi Experts, 🙂

 

I've been trying to automate break feature in one of drawing.

Please check snap I've attached below:

As shown in 1st snap I need to make a break which starts at 100 mm from left edge and ends at 250 mm from the same left edge. I've been working on model scale of 1 : 8. Model overall length is 3100 mm.

I understand that ilogic works on cm units so I've placed start and end points as 10 and 25 respectively in code. (Please check below code)

 

It's not giving result as I wanted.  I've posted result snap as well. (Please check 2nd snap) !!

 

Could anyone please help me understand that how these start and end points work ? in which unit do they work ? and also I believe they depends on scale as well but not getting how to set these points.

 

 

 

 

Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
Dim viewL = ActiveSheet.View("VIEW10")
Dim view = viewL.View
Dim i As Integer

	For i = 1 To 10
		
		If view.BreakOperations.Count<> 0 Then
		view.BreakOperations(1).Delete
		
		End If
	Next i

Dim oCenter As Point2d
oCenter = view.Center
Dim startPt As Point2d
Dim endPt As Point2d
startPt = ThisApplication.TransientGeometry.CreatePoint2d(10, oCenter.Y)
endPt = ThisApplication.TransientGeometry.CreatePoint2d(25, oCenter.Y)
Dim oBreakOperation As BreakOperation
oBreakOperation = view.BreakOperations.Add(BreakOrientationEnum.kHorizontalBreakOrientation, startPt, endPt,BreakStyleEnum.kStructuralBreakStyle, 10, 0.3)

 

0 Likes
Accepted solutions (1)
1,946 Views
9 Replies
Replies (9)
Message 2 of 10

WCrihfield
Mentor
Mentor

I believe that not only are you dealing with 'database units', but also with 'sheet space' distances rather than model space distances, and scale factor, as you suspected.  I'm thinking you would need to get the view's scale to a variable (Double), then multiply your expected offset values by that scale variable, before supplying them to the Add function.

The other problem, is your trying to judge where geometry is going to be within a view, by using the view's bounds, which isn't usually very accurate.  It would likely be more accurate, and more stable if you actually referenced a DrawingCurveSegment/DrawingCurve representing a model Edge, then maybe its mid point or end point position within the view.  It will be quite a bit more difficult to set-up that way, but drawing automation usually is a lot more complicated to do by code than it is to do manually.  You could probably assign a name to the Face or Edge in the Part document, then retrieve that Face or Edge in the rule, then determine which DrawingCurve in the view is representing that Face or Edge.  Then check its geometry type (likely a line), and create a Line variable and set this object as its value.  Then get the end point or mid point property of it to use in the break point placements.

 

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
Message 3 of 10

Anonymous
Not applicable

Hi @WCrihfield ,

 

Thanks for the response and helping me understand this.

Apparently I'm new to this CAD automation world.

If it's not a lot to ask could you please write code for this ? Not very much detailed but just to get an overall idea of what you're suggesting.

 

What I understand here is that I need to make 2 "named edges" (Rather can I make planes here ?) in part file for start and end point. Then retrieve these 2 lines (or planes if possible) position in drawing rule and make them as start and end point for break operation.  

 

Please correct me if I'm wrong here. Your simple code to understand this thing will be appreciated. Thanks in advance.

0 Likes
Message 4 of 10

WCrihfield
Mentor
Mentor
Accepted solution

Since I don't have your specific model and drawing to play with, I'm just 'shooting from the hip' here, in the general direction of your scenario.  This is just a quick, untested, rough draft of some iLogic code that should get you pointed in the right direction.  There are multiple ways to do some of these things, and many things that can be identified/retrieved differently within it, so you may need to change some things to get it to work for your specific situation.  Anyways, here's what I've thrown together for you, so far:

Sub Main
	'this rule is designed to be ran within a DrawingDocument
	'get the target drawing document
	Dim oDDoc As DrawingDocument = ThisDrawing.Document
	
	'check that there 'is' a model document, first
	If ThisDrawing.ModelDocument Is Nothing Then
		MsgBox("There is no model document being represented in this drawing yet. Exiting.",,"")
		Exit Sub
	End If
	
	'now check which type of document the model is (assembly or part)
	If ThisDrawing.ModelDocument.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
		MsgBox("This rule only works when the model document is a Part. Exiting.", , "")
		Exit Sub
	End If
	'if it passed that check, it is a Part, so capture it in that Type of variable
	Dim oPDoc As PartDocument = ThisDrawing.ModelDocument
	
	'retrieve the named entities collection from the part document (only works with Part documents)
	Dim oNEs As NamedEntities = iLogicVb.Automation.GetNamedEntities(oPDoc)
	
	'the objects I named were Edge, so I'm expecting an Edge, so I defined the following variable's Type to be an Edge
	Dim oEdge1 As Edge = oNEs.TryGetEntity("Bottom Edge") 'the name you assigned to the Edge/Face
	If oEdge1 Is Nothing Then
		MsgBox("The first named entity was not found in the model part.  Exiting.", , "")
		Exit Sub
	End If
	Dim oEdge2 As Edge = oNEs.TryGetEntity("First Step Top Edge") 'the name assigned to the other Edge/Face
	If oEdge2 Is Nothing Then
		MsgBox("The second named entity was not found in the model part.  Exiting.", , "")
		Exit Sub
	End If
	
	'specify which view on which sheet you are going to be working with
	Dim oView As DrawingView = oDDoc.ActiveSheet.DrawingViews.Item(1)
	
	'try to identify which Edge resulted in which DrawingCurve shown in the view
	Dim oCurve1, oCurve2 As DrawingCurve
	For Each oDC As DrawingCurve In oView.DrawingCurves
		If oDC.ModelGeometry Is oEdge1 Then
			oCurve1 = oDC
		ElseIf oDC.ModelGeometry Is oEdge2 Then
			oCurve2 = oDC
		End If
	Next
	If oCurve1 Is Nothing Then
		MsgBox("Did not find a DrawingCurve in that view for the first named model Edge. Exiting.", , "")
		Exit Sub
	End If
	If oCurve2 Is Nothing Then
		MsgBox("Did not find a DrawingCurve in that view for the second named model Edge. Exiting.", , "")
		Exit Sub
	End If
	
	'try to get Point2d data from the two DrawingCurves that we can use
	Dim oPt1 As Point2d = oCurve1.CenterPoint
	Dim oPt2 As Point2d = oCurve2.CenterPoint
	
	'create your break operation
	Dim oBrOp As BreakOperation
	oBrOp = oView.BreakOperations.Add(BreakOrientationEnum.kHorizontalBreakOrientation, oPt1, oPt2, BreakStyleEnum.kStructuralBreakStyle)
End Sub

 

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)

0 Likes
Message 5 of 10

Anonymous
Not applicable

Hi @WCrihfield 

 

Thanks for the code. This was really helpful for me to understand.

There was just a minor update, instead of "TryGetEntity" I've replaced it with "FindEntity" (Though I didn't understand why "TryGetEntity" hasn't worked, but anyways this update has worked for me. Thanks again !) 

 

moving further in my mission to expedite learning of Automation. 🙂 There're few points I want to understand related to this automating break operation in Assembly model.

 

  • As for part model we've used named entity command to name the Edge / Face, Could we use this method in Assembly model as well ?? Coz I couldn't find a way to create named entity in Assembly. (Please note I don't want to make named face / edge in child part and then retrieve them in assembly model. This'd be very long process just only for break automation in drawing.)
  • First question has led me to second one.. If this "named entity" method doesn't work for Assembly, then could we find a way to make break in view from position of the "workplane." ?? So by just moving a workplane position in assembly, break feature in drawing gets updated ?? If you could write just a simple code for this it would be beneficial for me to understand how these features work in drawing automation.

Thanks for your help 🙂

0 Likes
Message 6 of 10

Jordan_jake
Explorer
Explorer

Im trying to use this code but Im getting this error. 

Jordan_jake_0-1729654365378.png

Jordan_jake_1-1729654412234.png

 

 

0 Likes
Message 7 of 10

jdasilvaS39UQ
Advocate
Advocate

Another method to automate the break points. Add two work points to your part called Break Start and Break End and your drawing will add a break using those points

 

Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document

Dim oSheet = oDoc.Sheets(1)

Dim oView As DrawingView

Dim i As Integer

For i = 1 To oSheet.DrawingViews.Count
	If oSheet.DrawingViews(i).Name = "VIEW1" Then
		oView = oSheet.DrawingViews(i)
	End If
Next

' Delete all breaks in our view
If oView.BreakOperations.Count > 0 Then
	Dim loopOp As BreakOperation
	
	For Each loopOp In oView.BreakOperations
		loopOp.Delete
	Next
End If

ThisApplication.ActiveDocument.Update

' Get the origin of our part
Dim oDef As PartComponentDefinition
oDef = oView.ReferencedDocumentDescriptor.ReferencedDocument.ComponentDefinition

Dim oWP1 As WorkPoint
Dim oWP2
oWP1 = oDef.WorkPoints.Item("Break Start")
oWP2 = oDef.WorkPoints.Item("Break End")

Call oView.SetIncludeStatus(oWP1, True)
Call oView.SetIncludeStatus(oWP2, True)

Dim oCentermark As Centermark
oCentermark = oSheet.Centermarks.Item(oSheet.Centermarks.Count)

Dim oPt1 As Point2d
Dim oPt2 As Point2d

oPt1 = oSheet.Centermarks.Item(oSheet.Centermarks.Count - 1).Position
oPt2 = oSheet.Centermarks.Item(oSheet.Centermarks.Count).Position

' Hide centermarks
oSheet.Centermarks.Item(oSheet.Centermarks.Count - 1).Visible = False
oSheet.Centermarks.Item(oSheet.Centermarks.Count).Visible = False

If oPt1.X > oPt2.X Then
	Dim oBrOp As BreakOperation
	oBrOp = oView.BreakOperations.Add(BreakOrientationEnum.kHorizontalBreakOrientation, oPt1, oPt2, BreakStyleEnum.kStructuralBreakStyle)
End If

 

 

0 Likes
Message 8 of 10

Jordan_jake
Explorer
Explorer

I used this code and it shows this error. 

Jordan_jake_0-1734426877291.png

can a workplane be used instead a workpoint?

0 Likes
Message 9 of 10

Jordan_jake
Explorer
Explorer

hi, how did you put distance from edge of the assigned entity name to the breakpoint feature. I used the code by WCrihfield, but the breakfeature generated is from end to end point of the part. That's why my part looks like this.

Jordan_jake_0-1734435481048.png

 

 

0 Likes
Message 10 of 10

jdasilvaS39UQ
Advocate
Advocate

No, it has to be a workpoint with how the code is set up. It translates the workpoints from your model to centermarks on the drawing. Those points are what are used to determine the break location

0 Likes