How to change offset value of existing workplane in Assembly

How to change offset value of existing workplane in Assembly

J.VandeMerckt
Advocate Advocate
306 Views
1 Reply
Message 1 of 2

How to change offset value of existing workplane in Assembly

J.VandeMerckt
Advocate
Advocate

Hi Everyone.

I'm trying to write a code which adds a workplane in a assembly.
I can add the workplane but can only use a Double for the offset. (I would like to use a string which references some user parameters.

So my idea was to place the Workplane using Ilogic and change the offset afterwards in the same code and then use the string value.

The Code I'm using to place the Workplane is this:

Sub AddPlanes'Check and add Mid and Back plane if needed
	oDef = ThisDoc.Document.ComponentDefinition
	Dim pOffsetRightplane As String = "pCcLength / 2"
	Dim pOffsetLeftplane As String = "-pCcLength / 2"
	Dim oWPlaneRight As WorkPlane
	Dim oWPlaneLeft As WorkPlane

	oWPlaneRight = AddWorkPlaneInAssemblyOffset(oDef.WorkPlanes("XZ Plane (Right)"), 1)
	oWPlaneRight.Name = "CC Right"

	oWPlaneRight = AddWorkPlaneInAssemblyOffset(oDef.WorkPlanes("XZ Plane (Right)"), -1)
	oWPlaneRight.Name = "CC Left"
	
	oWPlaneRight.Offset.Expression = pOffsetRightplane
    oWPlaneLeft.OffseI'm t.Expression = pOffsetLeftplane
	
	
End Sub

Function AddWorkPlaneInAssemblyOffset(oFace As Object, oOffset As Double) As WorkPlane
	Dim uOM As UnitsOfMeasure = ThisDoc.Document.UnitsOfMeasure
	Dim oAsm As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
	Dim oOriginPnt As Point
	Dim oXaxis As UnitVector
	Dim oYaxis As UnitVector
	oOriginPnt = ThisApplication.TransientGeometry.CreatePoint(0#, 0#, 0#)
	oXaxis = ThisApplication.TransientGeometry.CreateUnitVector(1#, 0#, 0#)
	oYaxis = ThisApplication.TransientGeometry.CreateUnitVector(0#, 1#, 0#)
	Dim oPlane As WorkPlane = oDef.WorkPlanes.AddFixed(oOriginPnt, oXaxis, oYaxis)
	oPlane.AutoResize = True
	oDef.Constraints.AddFlushConstraint(oFace, oPlane, uOM.ConvertUnits(oOffset, uOM.LengthUnits, UnitsTypeEnum.kDatabaseLengthUnits))
	oPlane.AutoResize = False
	Return oPlane
End Function

This is the Code which should change the existing offset to my string value but it doesn't work.

	oWPlaneRight.Offset.Expression = pOffsetRightplane    oWPlaneLeft.Offset.Expression = pOffsetLeftplane

 I'm getting this error.

Error on line 50 in rule: CCLength for rails, in document: CAD0006625.iam

Public member 'Offset' on type 'WorkPlane' not found.
I've underlined Line 50.

Can anyone help me with changing the existing value to a string value?
Br

Justin

0 Likes
Accepted solutions (1)
307 Views
1 Reply
Reply (1)
Message 2 of 2

J.VandeMerckt
Advocate
Advocate
Accepted solution

Ok so after posting this I realised I needed to change the value of the constraint of the new Workplane.


This is the working Code:

Sub AddPlanes
	oDef = ThisDoc.Document.ComponentDefinition
	Dim pOffsetRightplane As String = "pCcLength / 2"
	Dim pOffsetLeftplane As String = "-pCcLength / 2"
	Dim oWPlaneRight As WorkPlane
	Dim oWPlaneLeft As WorkPlane
	Dim oRightConstraint As FlushConstraint
	Dim oLeftConstraint As FlushConstraint

	oWPlaneRight = AddWorkPlaneInAssemblyOffset(oDef.WorkPlanes("XZ Plane (Right)"), 1, oRightConstraint)
	oWPlaneRight.Name = "CC Right"
	oRightConstraint.Offset.Expression = pOffsetRightplane

	oWPlaneRight = AddWorkPlaneInAssemblyOffset(oDef.WorkPlanes("XZ Plane (Right)"), -1, oLeftConstraint)
	oWPlaneRight.Name = "CC Left"
	oLeftConstraint.Offset.Expression = pOffsetLeftplane
End Sub

Function AddWorkPlaneInAssemblyOffset(oFace As Object, oOffset As Double,ByRef oConstraint As FlushConstraint) As WorkPlane
	Dim uOM As UnitsOfMeasure = ThisDoc.Document.UnitsOfMeasure
	Dim oAsm As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
	Dim oOriginPnt As Point
	Dim oXaxis As UnitVector
	Dim oYaxis As UnitVector
	oOriginPnt = ThisApplication.TransientGeometry.CreatePoint(0#, 0#, 0#)
	oXaxis = ThisApplication.TransientGeometry.CreateUnitVector(1#, 0#, 0#)
	oYaxis = ThisApplication.TransientGeometry.CreateUnitVector(0#, 1#, 0#)
	Dim oPlane As WorkPlane = oDef.WorkPlanes.AddFixed(oOriginPnt, oXaxis, oYaxis)
	oPlane.AutoResize = True
	oConstraint = oDef.Constraints.AddFlushConstraint(oFace, oPlane, uOM.ConvertUnits(oOffset, uOM.LengthUnits, UnitsTypeEnum.kDatabaseLengthUnits))
	oPlane.AutoResize = False
	Return oPlane
End Function



0 Likes