Changing the parameter value in the form creates a new feature

Changing the parameter value in the form creates a new feature

tomas.bangoA2EPZ
Advocate Advocate
701 Views
8 Replies
Message 1 of 9

Changing the parameter value in the form creates a new feature

tomas.bangoA2EPZ
Advocate
Advocate

Hello, I am a complete beginner and would appreciate any help.


I would like to create a simple "configurator" .J shaped profile drawn to a certain parameter value. The problem appears when I change the parameter value in the form. The change restarts the rule it creates a new feature with the new parameter value

I would like the form to change the value in an already created feature and not create a new one. Is that possible?

0 Likes
Accepted solutions (1)
702 Views
8 Replies
Replies (8)
Message 2 of 9

A.Acheson
Mentor
Mentor

Welcome to the forum. Can you please post the rule your using along with a simple file part showing your workflow. A couple of screenshots will help as well. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 9

tomas.bangoA2EPZ
Advocate
Advocate

Hello i have predefined paramter (del) 

 

Here is rule:

Dim oprt1 As PartDocument
	oprt1 = ThisApplication.ActiveDocument
	
Dim ocomp1 As PartComponentDefinition 
	ocomp1 = oprt1.ComponentDefinition

Dim osketch1 As PlanarSketch
osketch1=ocomp1.Sketches.Add(ocomp1.WorkPlanes(1))


Dim otgeo As TransientGeometry
otgeo=ThisApplication.TransientGeometry

Dim jcko As SketchArc
Dim jcko1 As SketchLine

jcko = osketch1.SketchArcs.AddByCenterStartEndPoint(otgeo.CreatePoint2d(0, 0), otgeo.CreatePoint2d(0, 10), otgeo.CreatePoint2d(0, -10), True)
jcko1 = osketch1.SketchLines.AddByTwoPoints(osketch1.SketchArcs.Item(1).StartSketchPoint, otgeo.CreatePoint2d(50, 10))
jcko1 = osketch1.SketchLines.AddByTwoPoints(osketch1.SketchLines.Item(1).EndSketchPoint, otgeo.CreatePoint2d(50, 5))
jcko1 = osketch1.SketchLines.AddByTwoPoints(osketch1.SketchLines.Item(2).EndSketchPoint, otgeo.CreatePoint2d(0, 5))
jcko = osketch1.SketchArcs.AddByCenterStartEndPoint(otgeo.CreatePoint2d(0, 0), osketch1.SketchLines.Item(3).EndSketchPoint, otgeo.CreatePoint2d(0, -5), True)
jcko1=osketch1.SketchLines.AddByTwoPoints(osketch1.SketchArcs.Item(1).EndSketchPoint,osketch1.SketchArcs.Item(2).EndSketchPoint)

Dim profil01 As Profile
profil01=osketch1.Profiles.AddForSolid

Dim oFeat1 As ExtrudeFeature
    oFeat1 = ocomp1.Features.ExtrudeFeatures.AddByDistanceExtent(profil01, del, kPositiveExtentDirection, kJoinOperation)
   
0 Likes
Message 4 of 9

WCrihfield
Mentor
Mentor

If your local parameter is called "del", then I can see why this rule is running every time the value of that parameter changes.  In a local (saved within a document) iLogic rule contains the unquoted name of a parameter that exists in that same document, then every time the value of that parameter changes it will cause this rule to run.  Try getting the value of that parameter in a different way and store it in a variable, without leaving it's name unquoted, then use that variable instead of 'del' in that last line of code.

So, try replacing this:

Dim oFeat1 As ExtrudeFeature
oFeat1 = ocomp1.Features.ExtrudeFeatures.AddByDistanceExtent(profil01, del, kPositiveExtentDirection, kJoinOperation)

with this:

Dim oDel As Double = Parameter("del")
Dim oFeat1 As ExtrudeFeature
oFeat1 = ocomp1.Features.ExtrudeFeatures.AddByDistanceExtent(profil01, oDel, kPositiveExtentDirection, kJoinOperation)

 That should eliminate it running automatically every time the value of that parameter changes.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 9

tomas.bangoA2EPZ
Advocate
Advocate

Thank you it works perfectly and, is there a way to prevent the creation of new features every time i run the rule?

0 Likes
Message 6 of 9

WCrihfield
Mentor
Mentor

Yes.  That can be done to, if you want it that way.  Basically we could have it search for the existing feature first, and if it already exists, then don't proceed to create it again.  It's usually best to do this by the feature's name, but if you only have one extrude feature in your model (and it will always be that way) we can just look for the first extrude feature.  Then if it doesn't find one, proceed through the rest of your code to create it.  You can also add an additional line of code after you create the feature to give it a specific name if you wanted.  That would ensure it will be named what you are expecting to find the next time.  Is this what you want?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 9

tomas.bangoA2EPZ
Advocate
Advocate

Because what you describe is a bit beyond my skills I tried something similar and I'm very glad we came across it.

 

In the rule I'm trying to delete a sketch named Profile and then create it this works for me.

	
Dim oSketch As Sketch
    oSketches = ocomp1.Sketches
For Each oSketch In oSketches
If oSketch.Name = "Profil" Then
   oSketch.Delete
Return
End If
Next

'Dim oVys As ExtrudeFeature
'	oVysu = ocomp1.ExtrudeFeatures
'For Each oVys In oVysu	
'If oVys.Name = "VLko" Then
'	oVys.Delete
'Return	
'End If
'Next



Dim osketch1 As PlanarSketch
osketch1=ocomp1.Sketches.Add(ocomp1.WorkPlanes(1))
osketch1.Name="Profil"

Dim otgeo As TransientGeometry
otgeo=ThisApplication.TransientGeometry

Dim jcko As SketchArc
Dim jcko1 As SketchLine

jcko = osketch1.SketchArcs.AddByCenterStartEndPoint(otgeo.CreatePoint2d(0, 0), otgeo.CreatePoint2d(0, 10), otgeo.CreatePoint2d(0, -10), True)
jcko1 = osketch1.SketchLines.AddByTwoPoints(osketch1.SketchArcs.Item(1).StartSketchPoint, otgeo.CreatePoint2d(50, 10))
jcko1 = osketch1.SketchLines.AddByTwoPoints(osketch1.SketchLines.Item(1).EndSketchPoint, otgeo.CreatePoint2d(50, 5))
jcko1 = osketch1.SketchLines.AddByTwoPoints(osketch1.SketchLines.Item(2).EndSketchPoint, otgeo.CreatePoint2d(0, 5))
jcko = osketch1.SketchArcs.AddByCenterStartEndPoint(otgeo.CreatePoint2d(0, 0), osketch1.SketchLines.Item(3).EndSketchPoint, otgeo.CreatePoint2d(0, -5), True)
jcko1=osketch1.SketchLines.AddByTwoPoints(osketch1.SketchArcs.Item(1).EndSketchPoint,osketch1.SketchArcs.Item(2).EndSketchPoint)

Dim profil01 As Profile
profil01=osketch1.Profiles.AddForSolid

'Dim oDel As Double = Parameter("del")
'Dim oFeat1 As ExtrudeFeature
'oFeat1 = ocomp1.Features.ExtrudeFeatures.AddByDistanceExtent(profil01, oDel, kPositiveExtentDirection, kJoinOperation)
'    oFeat1.Name = "VLko"
	

But if I try it with extrudefeature I get an error. (ExtrudeFeatures type PartComponentDefinition was not found)

Dim oprt1 As PartDocument
	oprt1 = ThisApplication.ActiveDocument
	
Dim ocomp1 As PartComponentDefinition 
	ocomp1 = oprt1.ComponentDefinition
	
	
'Dim oSketch As Sketch
'    oSketches = ocomp1.Sketches
'For Each oSketch In oSketches
'If oSketch.Name = "Profil" Then
'   oSketch.Delete
'Return
'End If
'Next

Dim oVys As ExtrudeFeature
	oVysu = ocomp1.ExtrudeFeatures
For Each oVys In oVysu	
If oVys.Name = "VLko" Then
	oVys.Delete
Return	
End If
Next



Dim osketch1 As PlanarSketch
osketch1=ocomp1.Sketches.Add(ocomp1.WorkPlanes(1))
osketch1.Name="Profil"

Dim otgeo As TransientGeometry
otgeo=ThisApplication.TransientGeometry

Dim jcko As SketchArc
Dim jcko1 As SketchLine

jcko = osketch1.SketchArcs.AddByCenterStartEndPoint(otgeo.CreatePoint2d(0, 0), otgeo.CreatePoint2d(0, 10), otgeo.CreatePoint2d(0, -10), True)
jcko1 = osketch1.SketchLines.AddByTwoPoints(osketch1.SketchArcs.Item(1).StartSketchPoint, otgeo.CreatePoint2d(50, 10))
jcko1 = osketch1.SketchLines.AddByTwoPoints(osketch1.SketchLines.Item(1).EndSketchPoint, otgeo.CreatePoint2d(50, 5))
jcko1 = osketch1.SketchLines.AddByTwoPoints(osketch1.SketchLines.Item(2).EndSketchPoint, otgeo.CreatePoint2d(0, 5))
jcko = osketch1.SketchArcs.AddByCenterStartEndPoint(otgeo.CreatePoint2d(0, 0), osketch1.SketchLines.Item(3).EndSketchPoint, otgeo.CreatePoint2d(0, -5), True)
jcko1=osketch1.SketchLines.AddByTwoPoints(osketch1.SketchArcs.Item(1).EndSketchPoint,osketch1.SketchArcs.Item(2).EndSketchPoint)

Dim profil01 As Profile
profil01=osketch1.Profiles.AddForSolid

Dim oDel As Double = Parameter("del")
Dim oFeat1 As ExtrudeFeature
oFeat1 = ocomp1.Features.ExtrudeFeatures.AddByDistanceExtent(profil01, oDel, kPositiveExtentDirection, kJoinOperation)
    oFeat1.Name = "VLko"
	

 

0 Likes
Message 8 of 9

WCrihfield
Mentor
Mentor
Accepted solution

I think you just missed a step when trying to get the ExtrudeFeatures object.

Instead of this:

oVysu = ocomp1.ExtrudeFeatures

it should have been this:

oVysu = ocomp1.Features.ExtrudeFeatures

This version might work for you.

Dim oprt1 As PartDocument = ThisApplication.ActiveDocument
Dim ocomp1 As PartComponentDefinition = oprt1.ComponentDefinition

'check to see if this feature already exists

'create a Boolean type parameter to record if we find it or not
Dim oFound As Boolean = False

'check for it by name with this code
If ocomp1.Features.ExtrudeFeatures.Count > 0 Then
	For Each oEF As ExtrudeFeature In ocomp1.Features.ExtrudeFeatures
		'<<<< CHANGE THIS FEATURE NAME TO MATCH YOURS >>>>
		If oEF.Name = "My Extrude Feature" Then
			'it was found
			oFound = True
		End If
	Next
Else
	'there were no extrude features yet
	oFound = False 'not necessary, because it would still be False already
End If

If oFound = True Then 'it was found, so don't do anything and exit the rule
	Exit Sub 'or Return 'this will exit the rule
ElseIf oFound = False Then 'it was not found, so create it
	Dim osketch1 As PlanarSketch = ocomp1.Sketches.Add(ocomp1.WorkPlanes(1))
	Dim otgeo As TransientGeometry = ThisApplication.TransientGeometry
	Dim jcko As SketchArc
	Dim jcko1 As SketchLine

	jcko = osketch1.SketchArcs.AddByCenterStartEndPoint(otgeo.CreatePoint2d(0, 0), otgeo.CreatePoint2d(0, 10), otgeo.CreatePoint2d(0, -10), True)
	jcko1 = osketch1.SketchLines.AddByTwoPoints(osketch1.SketchArcs.Item(1).StartSketchPoint, otgeo.CreatePoint2d(50, 10))
	jcko1 = osketch1.SketchLines.AddByTwoPoints(osketch1.SketchLines.Item(1).EndSketchPoint, otgeo.CreatePoint2d(50, 5))
	jcko1 = osketch1.SketchLines.AddByTwoPoints(osketch1.SketchLines.Item(2).EndSketchPoint, otgeo.CreatePoint2d(0, 5))
	jcko = osketch1.SketchArcs.AddByCenterStartEndPoint(otgeo.CreatePoint2d(0, 0), osketch1.SketchLines.Item(3).EndSketchPoint, otgeo.CreatePoint2d(0, -5), True)
	jcko1= osketch1.SketchLines.AddByTwoPoints(osketch1.SketchArcs.Item(1).EndSketchPoint,osketch1.SketchArcs.Item(2).EndSketchPoint)

	Dim profil01 As Profile = osketch1.Profiles.AddForSolid
	
	Dim oDel As Double = Parameter("del")
	Dim oFeat1 As ExtrudeFeature
	oFeat1 = ocomp1.Features.ExtrudeFeatures.AddByDistanceExtent(profil01, oDel, kPositiveExtentDirection, kJoinOperation)
	'<<<< CHANGE THIS FEATURE NAME TO MATCH YOURS >>>>
	oFeat1.Name = "My Extrude Feature"
End If

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 9

tomas.bangoA2EPZ
Advocate
Advocate

jeez that was it thank you very much that adding .Features do the trick :DD thx again

0 Likes