Need iLogic for Model sketch auto Constraint

Need iLogic for Model sketch auto Constraint

gparamasivam
Enthusiast Enthusiast
508 Views
2 Replies
Message 1 of 3

Need iLogic for Model sketch auto Constraint

gparamasivam
Enthusiast
Enthusiast

Hi all,

 

Please see the attachment.

Currently i am using the below iLogic rule for deleting the horizontal and vertical constraints in model sketch.

 
Dim oPartDoc As PartDocument
Dim oSketch As PlanarSketch

Dim geoconstraint As GeometricConstraint

On Error Resume Next

oPartDoc = ThisApplication.ActiveDocument

For Each oSketch In oPartDoc.ComponentDefinition.Sketches
For Each geoconstraint In oSketch.GeometricConstraints
	If geoconstraint.Type = kHorizontalConstraintObject Then
		'MsgBox ("Deleting Horizontal Constraints")
Call geoconstraint.Delete
Else If geoconstraint.Type = kVerticalConstraintObject Then
			'MsgBox ("Deleting Vertical Constraints")
Call geoconstraint.Delete
End If
Next geoconstraint

Next oSketch

MsgBox ("All Horizontal and Vertical constraints deleted!")

 

tempsnip.jpg

But we need to after deleting the horizontal and vertical constraints, the sketch line should be auto constraints by using the XY master Plane (Projection line) or XZ master plane (Center line) arrest with parallel or perpendicular constraints

Hope you understand...

0 Likes
Accepted solutions (1)
509 Views
2 Replies
Replies (2)
Message 2 of 3

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @gparamasivam 

I think I understand what you're asking for. Assuming all horizontal constraints should be replaced by parallel constraints to XY-plane and all vertical constraints should be replaced with parallel constraints to the XZ-plane this should do it 🙂

Dim oPartDoc As PartDocument
Dim oSketch As PlanarSketch

Dim geoconstraint As GeometricConstraint

On Error Resume Next

oPartDoc = ThisApplication.ActiveDocument

Dim XZPlane As WorkPlane = oPartDoc.ComponentDefinition.WorkPlanes("XZ Plane")
Dim XYPlane As WorkPlane = oPartDoc.ComponentDefinition.WorkPlanes("XY Plane")

For Each oSketch In oPartDoc.ComponentDefinition.Sketches


	Dim oLineXZ As SketchLine = Nothing
	Dim oLineXY As SketchLine = Nothing

	For Each sLine As SketchLine In oSketch.SketchLines
		If sLine.ReferencedEntity Is XZPlane Then oLineXZ = sLine
		If sLine.ReferencedEntity Is XYPlane Then oLineXY = sLine
	Next

	If oLineXZ Is Nothing Then oLineXZ = oSketch.AddByProjectingEntity(XZPlane)
	If oLineXY Is Nothing Then oLineXY = oSketch.AddByProjectingEntity(XYPlane)

	For Each geoconstraint In oSketch.GeometricConstraints
		If geoconstraint.Type = ObjectTypeEnum.kHorizontalConstraintObject Then
			'MsgBox ("Deleting Horizontal Constraints")
			Dim oLine As SketchLine = geoconstraint.Entity
			Call geoconstraint.Delete
			oSketch.GeometricConstraints.AddParallel(oLine, oLineXY)
		Else If geoconstraint.Type = ObjectTypeEnum.kVerticalConstraintObject Then
		Dim oLine As SketchLine = geoconstraint.Entity
		'MsgBox ("Deleting Vertical Constraints")
		Call geoconstraint.Delete
		oSketch.GeometricConstraints.AddParallel(oLine, oLineXZ)
		End If
	Next geoconstraint

Next oSketch

MsgBox("All Horizontal and Vertical constraints deleted!")
Message 3 of 3

gparamasivam
Enthusiast
Enthusiast

Thanks for your quick solution,...

0 Likes