Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: SpokenEarth

For some reason, it's not letting me toggle the Driven property of those dimension constraints between True & False.  It seems like it will let me toggle one, but not the other.  I know you have to do it in the right order, or it will throw an error, because you can't have two driving dimension trying to control the same fully constrained sketch entity, so I'm being careful with that, but still getting an error.  I am also aware that when you toggle a sketch dimension between 'driving' and 'driven' it also switches the parameter that the dimension represents between being a regular model parameter and being a reference parameter.  Maybe this has something to do with it.  For some reason it is thinking that a dimension (the ID dimension) is 'Driven', when it's not, and is trying to set it to 'driving', which I believe is where the error is happening.  I'm not sure how to deal with that situation, since it seems to be a 'Bug'.

 

Anyways, here is the iLogic rule I created for your provided part document.  I believe it is finding the dimensions OK, just not toggling their 'Driven' property correctly.  I had a ton of Msgbox's in there before trying to track down where the error is happening, and why, but have removed most of them, leaving the Try...Catch blocks in there for now.  I know where the error is happening (mentioned above), just not sure how to fix it.

Dim oPDoc As PartDocument = ThisDoc.Document
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oSketch As PlanarSketch
Try
	oSketch = oPDef.Sketches.Item("SK BS 4825-3")
Catch
	MsgBox("Couldn't find that sketch.  Exiting Rule.", , "")
	Exit Sub
End Try
oPDoc.Update2(True)
oSketch.Edit
'identify the 3 dimensions
Dim oID, oOD, oThickness As DimensionConstraint
For Each oDC As DimensionConstraint In oSketch.DimensionConstraints
	If oDC.Parameter.Name = "BS4825:1" Then
		oID = oDC
		MsgBox("oID was found.  It's value is " & oID.Parameter.Value.ToString,,"")
	ElseIf oDC.Parameter.Name = "BS4825:2" Then
		oOD = oDC 'we're leaving this one alone for now
		MsgBox("oOD was found.  It's value is " & oOD.Parameter.Value.ToString,,"")
	ElseIf oDC.Parameter.Name = "d109" Then
		oThickness = oDC
		MsgBox("oThickness was found.  It's value is " & oThickness.Parameter.Value.ToString,,"")
	End If
Next
'make sure we've got them
If IsNothing(oID) Or IsNothing(oOD) Or IsNothing(oThickness) Then Exit Sub
	
'now try to toggle them
'toggling needs to happen in correct order, or it will throw an error
If oID.Driven = True And oThickness.Driven = False Then
	MsgBox("oID.Diven = True And oThickness.Driven = False")
	Try
		oID.Driven = False
		MsgBox("Just toggled oID.Diven to False")
	Catch oEx As Exception
		MsgBox("oID.Driven was True.  Failed to toggle it to False." & vbCrLf & _
		oEx.Message & vbCrLf & vbCrLf & _
		oEx.StackTrace & vbCrLf & vbCrLf & _
		oEx.Source,,"")
	End Try
	oPDoc.Update2(True)
	Try
		oThickness.Driven = True
		MsgBox("Just toggled oThickness.Diven to True")
	Catch oEx As Exception
		MsgBox("oThickness.Driven was False.  Failed to toggle it to True." & vbCrLf & _
		oEx.Message & vbCrLf & vbCrLf & _
		oEx.StackTrace & vbCrLf & vbCrLf & _
		oEx.Source,,"")
	End Try
ElseIf oID.Driven = False And oThickness.Driven = True Then
	MsgBox("oID.Driven = False And oThickness.Driven = True")
	Try
		oThickness.Driven = False
		MsgBox("Just toggled oThickness.Diven to False")
	Catch oEx As Exception
		MsgBox("oThickness.Driven was True.  Failed to toggle it to False." & vbCrLf & _
		oEx.Message & vbCrLf & vbCrLf & _
		oEx.StackTrace & vbCrLf & vbCrLf & _
		oEx.Source,,"")
	End Try
	oPDoc.Update2(True)
	Try
		oID.Driven = True
		MsgBox("Just toggled oID.Diven to True")
	Catch oEx As Exception
		MsgBox("oID.Driven was False.  Failed to toggle it to True." & vbCrLf & _
		oEx.Message & vbCrLf & vbCrLf & _
		oEx.StackTrace & vbCrLf & vbCrLf & _
		oEx.Source,,"")
	End Try
End If
oSketch.ExitEdit
oPDoc.Update2(True)

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) :thumbs_up:.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :light_bulb:or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)