make centermark with Ilogic

make centermark with Ilogic

Darkforce_the_ilogic_guy
Advisor Advisor
3,206 Views
25 Replies
Message 1 of 26

make centermark with Ilogic

Darkforce_the_ilogic_guy
Advisor
Advisor

I am trying to make some automation to making drawing and working on an illogic code to add Center mark to an drawing.

 

So far I can get it to centermart circular holes and all view..

 

The problem I still have that 

 

if I run the code again .. it will add one more centermark even if there already are one

 

the second thing.. is that I do not want one on my ISO view.

 

my code so far is like this

 

Sub main
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDoc.Document

Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet

Dim oView As DrawingView

 


For y = 1 To oSheet.DrawingViews.Count
 oView = oSheet.DrawingViews.Item(y)
Dim oCenterMarks As Centermarks
oCenterMarks = oSheet.Centermarks

 


Dim aoDrawCurves4 As DrawingCurve
oDrawViewCurves = oView.DrawingCurves(aoEdge4)
Dim aoDrawCurves4Count = oDrawViewCurves.Count

For i=1 To aoDrawCurves4Count
 

aoDrawCurves4 = oDrawViewCurves.item(i)

Dim oDim2 As Centermark

Try
 If aoDrawCurves4.CurveType.ToString = "kCircleCurve" Then
oDim2 = oCenterMarks.Add(oSheet.CreateGeometryIntent(aoDrawCurves4))
End If
Catch
 
End Try
Next
Next


End Sub

 

 

 

0 Likes
Accepted solutions (3)
3,207 Views
25 Replies
Replies (25)
Message 21 of 26

WCrihfield
Mentor
Mentor

Hi @DIMCWPDR.  Thanks for posting the files to test with.  Things got busy where I work, so I had to do some other things for a while, before working on this challenge.  But I think I have an iLogic rule that will work OK for you.  The biggest challenge here is that we had to use different strategies for different views.  The 'Front' view we were able to just use the 'Auto' tools on.  But the 'Side' / Projected view, we had to do things the hard way, to only add a centerline to the one main cylinder, without adding them to all the other holes.  The code for creating that one centerline may look a little complicated, but it seems to be working in my tests.

 

However, some preparation was needed in the model document first.  The part file already had two named entities in it, so I deleted those two, then assigned just one name to the outermost cylinder face of the whole part, and named it "Outside Cylinder Face".  I avoided naming any of the others, because the others may come and go with variations of the part, and simply do not need to be named to make this work.  You can name that face in your template part, then it should perpetuate to new parts made from it.  And other existing parts that you want to use this code on their drawings, just name that same face with the same name, then save that model file, before using this code on their drawings.

Dim oACS As AutomatedCenterlineSettings = ThisDrawing.Document.DrawingSettings.AutomatedCenterlineSettings
oACS.ApplyToCircularPatterns = True
oACS.ApplyToCylinders = True
oACS.ApplyToHoles = True
oACS.ApplyToRevolutions = True
oACS.ProjectionNormalAxis = True
oACS.ProjectionParallelAxis = True

Dim oSheet As Sheet = ActiveSheet.Sheet
For Each oView As DrawingView In oSheet.DrawingViews
	If oView.ViewType = DrawingViewTypeEnum.kProjectedDrawingViewType Then
		'its a projected view (like side view), so only create one centerline using iLogic
			'get model document being referenced by this view
			Dim oViewDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
			'get named face from model
			Dim oNamedFace As Face = iLogicVb.Automation.GetNamedEntities(oViewDoc).TryGetEntity("Outside Cylinder Face")
			If oNamedFace Is Nothing Then Continue For
			'get geometry of named face that is in this view
			Dim oViewGeomForNamedFace As DrawingCurvesEnumerator
			Try : oViewGeomForNamedFace = oView.DrawingCurves(oNamedFace) : Catch : End Try
			If oViewGeomForNamedFace Is Nothing OrElse oViewGeomForNamedFace.Count <> 4 Then Continue For
			Dim oGeomInt1, oGeomInt2 As GeometryIntent
			oGeomInt1 = oSheet.CreateGeometryIntent(oViewGeomForNamedFace.Item(3))
			oGeomInt2 = oSheet.CreateGeometryIntent(oViewGeomForNamedFace.Item(4))
			ActiveSheet.Centerlines.AddBisector("Outside Cylinder Centerline", oGeomInt1, oGeomInt2)
	Else 'it is base view, so create all centermarks & centerlines using 'auto' tools
		Dim oObjs As ObjectsEnumerator = oView.SetAutomatedCenterlineSettings(oACS)
	End If
Next

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 22 of 26

Curtis_Waguespack
Consultant
Consultant

@DIMCWPDR 

You can do all of this with the ilogic functions to add the center lines/marks, see the attached 2022 examples.

 

Note there is a rule in the part to rename the patterned work axes and turn off their visibility.

 

This is my result

Curtis_Waguespack_1-1723831046526.png

 

Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet:1")
Dim VIEW1 = Sheet_1.DrawingViews.ItemByName("VIEW1")
Dim VIEW11 = Sheet_1.DrawingViews.ItemByName("VIEW11")

Dim holeCenter = VIEW1.GetIntent("Center Hole Face", PointIntentEnum.kCenterPointIntent)
Dim centermark = Sheet_1.Centermarks.Add("Hole Centermark", holeCenter)

Dim oFrontFace = VIEW11.GetIntent("FrontFace")
Dim oBackFace = VIEW11.GetIntent("BackFace")

Dim centerline = Sheet_1.Centerlines.Add("Centerline", {oFrontFace, oBackFace } )

Dim oDoc = ActiveSheet.View("VIEW1").ModelDocument
i = 0
For Each oAxis As WorkAxis In oDoc.ComponentDefinition.WorkAxes
	If Not oAxis.IsCoordinateSystemElement Then
		VIEW1.NativeEntity.SetIncludeStatus(oAxis, True)
		i = i + 1
	End If
Next

Dim oListOfHoles = Nothing
If i >= 6 Then
	holePt1 = VIEW1.GetIntent("WkAxis1")
	holePt2 = VIEW1.GetIntent("WkAxis2")
	holePt3 = VIEW1.GetIntent("WkAxis3")
	holePt4 = VIEW1.GetIntent("WkAxis4")
	holePt5 = VIEW1.GetIntent("WkAxis5")
	holePt6 = VIEW1.GetIntent("WkAxis6")
	oListOfHoles = {holePt1, holePt2, holePt3, holePt4, holePt5, holePt6 }
End If

If i >= 7 Then 'add #7 and update the list
	holePt7 = VIEW1.GetIntent("WkAxis7")
	oListOfHoles = {holePt1, holePt2, holePt3, holePt4, holePt5, holePt6, holePt7 }
End If

If i >= 8 Then  'add #8 and update the list
	holePt8 = VIEW1.GetIntent("WkAxis8")
	oListOfHoles = {holePt1, holePt2, holePt3, holePt4, holePt5, holePt6, holePt7, holePt8 }
End If

Dim centerlinePattern = Sheet_1.Centerlines.AddCenteredPattern("Centerline Pattern", holeCenter, oListOfHoles)

EESignature

0 Likes
Message 23 of 26

Curtis_Waguespack
Consultant
Consultant

@WCrihfield wrote:

  The biggest challenge here is that we had to use different strategies for different views. 


@WCrihfield , I was able to get this to work with just ilogic functions. However it's not the most dynamic, as far as what happens if the hole pattern count changes. I kinda kludged it to show how to go from 6 to 8, but of course it would better if it could use any number of holes.

 

I would think it's doable to loop through the Axes as I have in this example, but create the compile oListOfHoles in a better way though. 

 

I tried a couple of things to create the IEnumerable list for the AddCenteredPattern function more dynamically, but I wasn't successful.

 

 

EESignature

0 Likes
Message 24 of 26

WCrihfield
Mentor
Mentor

I'm leaving for the day, but I'll say that I was hoping to avoid adding a bunch of work features.  My initial attempt at the centerline on the side view was attempting to use the GeometryIntent of the named cylindrical outer cylinder face, but as the point intent type, I wanted to use the axis start point and axis end point.  It would not allow that, even though the face appears to be a perfect cylinder.  Likely because there is no actual geometry representing its axis to attach to, not sure.  That's where a simple WorkAxis would have made it easier, but I didn't want to go that way.  Plus, I was not sure if a bunch of parts already existed, and may be ReadOnly.  But assigning names to geometry in all those models would dirty them, so that plan would not have worked either...just for the new stuff getting created from template.  If the code knows that there will always be a circular pattern, I suppose the 'Count' could be derived from that in the model, then use that count to drive quantities for loops in the code.  I may review it again tomorrow.  Have a good one.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 25 of 26

DIMCWPDR
Contributor
Contributor

Hi
I will be happy to see the resultat when you are done with it
Thanks

0 Likes
Message 26 of 26

DIMCWPDR
Contributor
Contributor

Hi

I thik i get this error when i run the "Rule1" in your idw part4, can you please check and advise

DIMCWPDR_0-1730123952782.png

 


 

0 Likes