iLogic: Redefine sketch loses constraint to center point

iLogic: Redefine sketch loses constraint to center point

diegojacobs
Participant Participant
630 Views
6 Replies
Message 1 of 7

iLogic: Redefine sketch loses constraint to center point

diegojacobs
Participant
Participant

I have a square tube.

I make a cut to one side of the tube using a sketch on the the XY plane. Sketch is contstrained to the center point

I want to use iLogic to redefine the sketch on the XZ plane.

 

I got it to work, but the sketch loses its constraint  to the center point.

When i manually redefine the sketch, it stays constrained to the center point. How do i do this in iLogic?

 

before redefinebefore redefineafter redefineafter redefine

 

code i currently have:

Dim oPD As PartDocument
    Dim oPCD As PartComponentDefinition
    Dim oSkt As PlanarSketch
    Dim oXZ As WorkPlane
    Dim oYZ As WorkPlane
    Dim oCentP As WorkPoint
    Dim oSktPt As SketchPoint
   
    oPD = ThisApplication.ActiveDocument
    oPCD = oPD.ComponentDefinition
    oXZ = oPCD.WorkPlanes.Item("XZ Plane")
    oYZ = oPCD.WorkPlanes.Item("YZ Plane")

    oCentP = oPCD.WorkPoints.Item(1)
   
    oSkt = oPCD.Sketches.Item("Sketch2")
   
    If oSkt.PlanarEntity Is oYZ Then
        oSkt.PlanarEntity = oXZ
	Else If oSkt.PlanarEntity Is oXZ Then
        oSkt.PlanarEntity = oYZ
    End If

 

0 Likes
Accepted solutions (2)
631 Views
6 Replies
Replies (6)
Message 2 of 7

dalton98
Collaborator
Collaborator

The point loses its reference when you change its plane. Couldn't tell you how this works, but if you re-project the center point it gets rid of the un-referenced one. Maybe it remembers that it was was projected even tho it doesnt have the reference anymore?

oSktPt = oSkt.AddByProjectingEntity(oCentP)
0 Likes
Message 3 of 7

diegojacobs
Participant
Participant

Hey thanks for your reply!

It kind of works.... but not really.

 

The sketch still shows up purple.

When i open the sketch, and try to drag it into a different position, it turns black/fully constrained.

but if i change anything about the geometry before opening and dragging the sketch it becomes clear the sketch is just floating.

 

So we got a step closer to getting the redefined sketch constrained, but not quite there.

0 Likes
Message 4 of 7

dalton98
Collaborator
Collaborator
Accepted solution

So it is fully constrained but u need to try and move it to get to show up? I encountered that same thing, it seemed to work if you change a dimension constraint. Ex:

oSkt.DimensionConstraints.Item(1).Driven = True
oSkt.DimensionConstraints.Item(1).Driven = False
0 Likes
Message 5 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Hi @diegojacobs.  If you have the setting called "Autoproject part origin on sketch create" turned on within your Application Options > Sketch tab, that point should automatically appear for you, but I don't recall if that applies to when you 'redefine' a sketch.  It is a very handy setting though.  @dalton98 was right about that SketchPoint loosing its reference though after redefining the sketch, because it was created by projection.  Can you tell if there is still a SketchPoint in the sketch after you have redefined the sketch?  If so, you may just need to re-constrain that point.  If not, then you would need to re-project the WorkPoint to the Sketch, which will create a new SketchPoint that will have a 'Fixed' constraint.  If you have to re-create the SketchPoint, then you will also most likely have to re-create the constraint between it and the other geometry in the sketch.  However, if the SketchPoint still exists, and you just ensure it is in the proper location and add a Fixed constraint to it again, the constraint(s) between it and the other sketch geometry will most likely be preserved, and OK.

I just created some geometry similar to yours in a new part document and tried to simulate what you are doing.  When I redefine the sketch manually, everything works just fine.  Cut works, & sketch stays fully constrained.  But when I set a different work plane by code it becomes unconstrained, due to the origin point loosing its reference.  I found a way to fix this with the code below:

 

Dim oPDoc As PartDocument = ThisDoc.Document
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oOriginPoint As WorkPoint = oPDef.WorkPoints.Item(1)
Dim oYZPlane As WorkPlane = oPDef.WorkPlanes.Item("YZ Plane")
Dim oXYPlane As WorkPlane = oPDef.WorkPlanes.Item("XY Plane")
Dim oSketch As PlanarSketch = oPDef.Sketches.Item("Sketch8")

'ReDefine Sketch
If oSketch.PlanarEntity Is oYZPlane Then
	oSketch.PlanarEntity = oXYPlane
ElseIf oSketch.PlanarEntity Is oXYPlane Then
	oSketch.PlanarEntity = oYZPlane
End If

'Find SketchPoint that represents Origin Point
Dim oOriginSP As SketchPoint
If oSketch.SketchPoints.Count > 1 Then
	For Each oSP As SketchPoint In oSketch.SketchPoints
		If oSP.ReferencedEntity Is oOriginPoint Then
			oOriginSP = oSP
		End If
	Next
	If IsNothing(oOriginSP) Then
		For Each oSP As SketchPoint In oSketch.SketchPoints
			If oSP.Geometry.X = 0 And oSP.Geometry.Y = 0 Then
				oOriginSP = oSP
			End If
		Next
	End If
End If
'if found, make sure it is fully constrained
If oOriginSP IsNot Nothing Then
	If oOriginSP.ConstraintStatus <> ConstraintStatusEnum.kFullyConstrainedConstraintStatus Then
		oSketch.GeometricConstraints.AddGround(oOriginSP)
	End If
Else 'sketch point representing origin or origin location was never found
	MsgBox("Origin SketchPoint was not found.",,"")
End If

 

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 6 of 7

diegojacobs
Participant
Participant

That's interesting! gonna try that tomorrow when I get back to work.

 

Here's what I think is happening.

 

Sketch gets moved to a new plane, it loses its reference to the centerpoint.

Next you project geometry of the centerpoint. Sketch stays undefined untill anything gets changed about the sketch which triggers it to iterate trough all its constraints. Then it finds the newly projected centerpoint and restores the constraint to it.

 

But the fact that everything work just fine when you manually redefine the sketch plane makes me believe it must be possible to code this.

 

Your suggestion might just be the perfect workaround tho. will report back tomorrow 🙂

0 Likes
Message 7 of 7

diegojacobs
Participant
Participant

@dalton98 @WCrihfield  It works!

You both had a different approach but both solutions gave the desired result, a fully constrained redefined sketch

0 Likes