ilogic Centerlines.AddCenteredPattern Method

ilogic Centerlines.AddCenteredPattern Method

leebrg
Contributor Contributor
651 Views
7 Replies
Message 1 of 8

ilogic Centerlines.AddCenteredPattern Method

leebrg
Contributor
Contributor

I am drawing a 3D model with a circular pattern using ilogic code. I want to add a pattern centerline to the part drawn as a circular pattern on the drawing. I tried to do it using the code below, but I don't understand objectcollection well... I don't know if I should put the drawing element, define a point, or use the name of the circular pattern...

If someone who knows better can tell me, I would be very grateful....

Please tell me exactly what arguments should be used when using the Centerlines.AddCenteredPattern Method.

I want to express it in the form of the picture below....
I hope someone who knows knows ..

 

leebridge_0-1729241207614.png

 

0 Likes
652 Views
7 Replies
Replies (7)
Message 2 of 8

Michael.Navara
Advisor
Advisor

This code sample demonstrates how to create center lines pattern.

The code assumes the drawing with one view from the part which contains single circular pattern from one hole. Otherwise the code becomes more complex.

 

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

	Dim part As PartDocument = drwView.ReferencedFile.DocumentDescriptor.ReferencedDocument
	Dim pattern As CircularPatternFeature = part.ComponentDefinition.Features.CircularPatternFeatures(1)


	Dim centerEntity As DrawingCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select center entity")
	Dim center = drwSheet.CreateGeometryIntent(centerEntity.Parent, PointIntentEnum.kCenterPointIntent)

	Dim centerEntities As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()
	Dim firstHoleCurve = drwView.DrawingCurves(pattern.ParentFeatures(1))(1)
	centerEntities.Add(drwSheet.CreateGeometryIntent(firstHoleCurve, PointIntentEnum.kCenterPointIntent))

	Dim curves As DrawingCurvesEnumerator = drwView.DrawingCurves(pattern)
	For Each curve As DrawingCurve In curves
		centerEntities.Add(drwSheet.CreateGeometryIntent(curve, PointIntentEnum.kCenterPointIntent))
	Next

	drwSheet.Centerlines.AddCenteredPattern(center, centerEntities, Closed :=True)
End Sub

 

MichaelNavara_0-1729245789034.png

 

0 Likes
Message 3 of 8

leebrg
Contributor
Contributor
Thank you for your kind reply.
However, I get an error saying that casting to Inventor.PartDocument is not possible.... I think it's because the current document is a drawing document. Is there another way?
0 Likes
Message 4 of 8

Michael.Navara
Advisor
Advisor

You need to run the rule from Drawing and the referenced model of the view is Part.

0 Likes
Message 5 of 8

leebrg
Contributor
Contributor

What if the referenced model of the view is an assembly? ㅜㅜ
It is not a single part, but several parts within the assembly forming a circular pattern....

0 Likes
Message 6 of 8

Michael.Navara
Advisor
Advisor

You need to look for appropriate occurrence and for getting drawing curve as argument in method drwView.DrawingCurves(...) you can't use native features HoleFeature and CircularPatternFeature but you must use its proxy representation in the context of the assembly (lines 13 and 17).

 

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

	Dim asm As AssemblyDocument = drwView.ReferencedFile.DocumentDescriptor.ReferencedDocument
	
	Dim partOcc As ComponentOccurrence = asm.ComponentDefinition.Occurrences(1)
	Dim partDef As PartComponentDefinition = partOcc.Definition 
	
	Dim pattern As CircularPatternFeature = partDef.Features.CircularPatternFeatures(1)
	Dim patternProxy As CircularPatternFeatureProxy
	partOcc.CreateGeometryProxy(pattern, patternProxy)
	
	Dim firstHole As HoleFeature = pattern.ParentFeatures(1)
	Dim firstHoleProxy As HoleFeatureProxy
	partOcc.CreateGeometryProxy(firstHole, firstHoleProxy)
	
	Dim centerEntity As DrawingCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select center entity")
	Dim center = drwSheet.CreateGeometryIntent(centerEntity.Parent, PointIntentEnum.kCenterPointIntent)

	Dim centerEntities As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()
	
	Dim firstHoleCurve = drwView.DrawingCurves(firstHoleProxy)(1)
	centerEntities.Add(drwSheet.CreateGeometryIntent(firstHoleCurve, PointIntentEnum.kCenterPointIntent))

	Dim curves As DrawingCurvesEnumerator = drwView.DrawingCurves(patternProxy)
	For Each curve As DrawingCurve In curves
		centerEntities.Add(drwSheet.CreateGeometryIntent(curve, PointIntentEnum.kCenterPointIntent))
	Next

	drwSheet.Centerlines.AddCenteredPattern(center, centerEntities, Closed :=True)
End Sub

 

0 Likes
Message 7 of 8

leebrg
Contributor
Contributor

I followed the instructions to code, but I got an error in the code Dim firstHole As HoleFeature = pattern.ParentFeature(1). After trying several things, I realized that I used a extrude feature instead of a hole when creating a circular pattern..... Could you please correct the code and let me know? Thank you so much and I'm sorry ㅠ.ㅠ

0 Likes
Message 8 of 8

Michael.Navara
Advisor
Advisor

Please don't confuse this forum with free code generator.

I try to show you how to use Centerlines.AddCenteredPattern() method. If you want to use this code, you need to understand it. Never use or run code if you are not sure what it does.

This requested modification is not hard. Try it yourself and if you get in trouble, post your version and I will help you to solve an issues.

0 Likes