use parameters in ilogic that haven't been created yet

use parameters in ilogic that haven't been created yet

neodd70
Enthusiast Enthusiast
305 Views
2 Replies
Message 1 of 3

use parameters in ilogic that haven't been created yet

neodd70
Enthusiast
Enthusiast

I am trying to create an external Form that has a button that when the user clicks it, it will run an external rule to create parameters in the part it is being used on. Then those parameters can then be used in another external rule to create a sketch, add a circle and extrude cut the circle from the part. The problem I am having is that I get an error until I open the external rule that tries to use the newly created parameters and then save it almost like it isn't seeing that the parameters are there until I edit the rule. Is there a way I can fix this or is there another way I can use a variable from a rule in a Form? 

0 Likes
306 Views
2 Replies
Replies (2)
Message 2 of 3

Sergio.D.Suárez
Mentor
Mentor

Hello, Could you attach your code to analyze it?
If you have confidential information, try to replicate the error in a simplified format. Perhaps the error is in the way in which the parameters are accessed. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 3 of 3

neodd70
Enthusiast
Enthusiast

@Sergio.D.Suárez  Here are the two rules I have. First is the rule to create the parameters

Dim oPartDoc As Document = ThisDoc.Document
Dim oPartCompDef As PartComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition

If oPartDoc.DocumentType = kPartDocumentObject Then
		
Dim oParams As Parameters = oPartCompDef.Parameters
				
		Dim oUserParams As UserParameters = oParams.UserParameters               
				
		Try
			oHoleSizes = oUserParams.Item("HoleSizes")
			Catch
oInsulationType = oUserParams.AddByValue("HoleSizes", 0, kInchLengthUnits) 
MultiValue.SetList("HoleSizes", .109375, .125, .15625, .1875, .21875, .28125)
			End Try
			
		Try
			oMaterial = oUserParams.Item("MaterialType")
			Catch
oInsulationType = oUserParams.AddByValue("MaterialType", " ", kTextUnits) 
MultiValue.SetList("MaterialType", "Starboard", "Acrylic", "Proboard")
			End Try
						
		Try
			oHoleType = oUserParams.Item("HoleType")
			Catch
oInsulationType = oUserParams.AddByValue("HoleType", " ", kTextUnits) 
MultiValue.SetList("HoleType", "Pilot", "Thru", "Custom")
			End Try

		Try
			oFromFrontEdge = oUserParams.Item("FromFrontEdge")
			Catch
oInsulationType = oUserParams.AddByValue("FromFrontEdge", (0.25 * 2.54), kInchLengthUnits) 
			End Try
		
		Try
			oFromLeftEdge = oUserParams.Item("FromLeftEdge")
			Catch
oInsulationType = oUserParams.AddByValue("FromLeftEdge", (1.125*2.54), kInchLengthUnits) 
			End Try
		
		Try
			oFromRightEdge = oUserParams.Item("FromRightEdge")
			Catch
oInsulationType = oUserParams.AddByValue("FromRightEdge", (1.125*2.54), kInchLengthUnits) 
			End Try

			End If
Parameter.UpdateAfterChange = True
MultiValue.UpdateAfterChange = True

next is a rule that needs to use those parameters to create a sketch of circles and extrude them. The parameters created by the first rule are what I want to have in a form. 

Dim oPartDoc As Document = ThisDoc.Document
Dim oPartCompDef As PartComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

'get measurements to determine Material Thickness
My_x = Measure.ExtentsLength
My_y = Measure.ExtentsWidth
My_z = Measure.ExtentsHeight

'Make longest value the Length, rounded to 4 places
oThickness = Round(MinOfMany(My_x, My_y, My_z), 4)

Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Surface to Place Holes")
Dim oFrontEdge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select Front Edge of Pattern")
Dim oVertex As Vertex = oFrontEdge.StartVertex

Dim oLeftEdge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select Left Edge of Pattern")
Dim oRightEdge As Edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Select Right Edge of Pattern")

oMaterial = MaterialType
oHoleType = HoleType
oHoleSize = HoleSizes * 2.54

Dim oSketch As PlanarSketch
'oSketch = oPartCompDef.Sketches.AddWithOrientation(oFace, oFrontEdge, True, True, oVertex, False)
oSketch = oPartCompDef.Sketches.Add(oFace, False)
oSketch.AxisEntity = oFrontEdge
oSketch.OriginPoint = oFrontEdge.StartVertex

Dim oSketchNameSuffix As Integer
Dim oNameCompare As String
Dim oNameNumCount As Integer
Dim oNameCharCount As Integer
If oHoleType = "Thru" Then
	oSketchNameSuffix = 0
	oNameCompare = "SK_Hole_"
	oNameCharCount = 8
	oNameNumCount = 9
Else If oHoleType = "Pilot" Then
	oSketchNameSuffix = 0
	oNameCompare = "SK_Pilot_"
	oNameCharCount = 9
	oNameNumCount = 10
End If

	For Each oSketchNameCheck As Sketch In oPartCompDef.Sketches
		If Left(oSketchNameCheck.Name,oNameCharCount) = oNameCompare Then
			oSketchNumber = Val(Mid(oSketchNameCheck.Name, oNameNumCount, 2))			
	        While oSketchNameSuffix <= oSketchNumber
				oSketchNameSuffix = oSketchNameSuffix + 1
			End While
		End If	
	Next 
	
oSketch.Name = oNameCompare & oSketchNameSuffix
Dim oQty = 4
oFromLeftEdge = FromLeftEdge * 2.54
oFromRightEdge = FromRightEdge * 2.54
oFromFrontEdge = FromFrontEdge * 2.54
Dim oFrontEdgeDistance = ThisApplication.MeasureTools.GetMinimumDistance(oFrontEdge.StartVertex, oFrontEdge.StopVertex)
Dim oPatternSpacing = (oFrontEdgeDistance -(oFromLeftEdge + oFromRightEdge)) / (oQty-1)

Dim oSketchPoint As SketchPoint = oSketch.SketchPoints.Add(oTG.CreatePoint2d(oFromLeftEdge, oFromFrontEdge))
Dim circleParentSketch As PlanarSketch = oSketchPoint.Parent
Dim vectorForCheck As UnitVector = circleParentSketch.PlanarEntityGeometry.Normal
Dim pointToCheck As Point = oSketchPoint.Geometry3d
Dim foundObjects As ObjectsEnumerator = Nothing
Dim locationPoints As ObjectsEnumerator = Nothing
oPartCompDef.FindUsingRay(pointToCheck, vectorForCheck, .00001, foundObjects, locationPoints)
If (foundObjects.Count = 0) Then
	oSketch.NaturalAxisDirection = True
Else If (foundObjects.Count > 0) Then
	oSketch.NaturalAxisDirection = False
End If

oSketchPoint.Delete

For i = 0 To oQty-1
	Dim oCircle As SketchCircle = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(oFromLeftEdge + (i * oPatternSpacing), oFromFrontEdge), (oHoleSize/2))
Next

Dim oProfile As Profile = oSketch.Profiles.AddForSolid

Dim oExtrude As ExtrudeFeature = oPartCompDef.Features.ExtrudeFeatures.AddByDistanceExtent(oProfile, oThickness*2.54, kNegativeExtentDirection, kCutOperation)
0 Likes