Reactions in Powercopies.pdf

(83 KB) Pobierz
Log in / create account
article
discussion
edit
history
Reactions in Powercopies
«««
(?)
Using reactions and powercopies, it is possible to create smart components that are truly generative.
One may create powercopies with a variable number of nested userfeatures or powercopies using either lists/loops or reactions. The
following article describes how to use reactions to create a parametric set of components.
The strategy in creating a component of this type is to:
1) Create a detailed and robust structure of nested geometric sets within the powercopy that will accomodate all necessary parameters,
reactions, construction geometry, and instantiated userfeatures.
2) Design the userfeature that will be instantiated in the powercopy and assign it a stable directory path.
3) Write the reaction that deletes old construction geometry and userfeatures, builds new construction geometry, and instantiates new
userfeatures.
In order for the reaction to update only the powercopy in which it is contained, the user must find the relative path of the containing
geometric set. The best way to do this is to hang the reaction on a geometric set contained inside the powercopy, so that the reaction can
navigate to the containing powercopy level using ".parent" syntax in VB.
Thus the parameters which fire the reaction should be contained in a geometric set, not a parameter set, since the parent of a parameter
set is the part, not the geometric set containing the powercopy. Also if a reaction is contained in a powercopy it should not be hung on a
parameter directly: if this happens, when the reaction is fired it will not be able to easily find the path to the other geometry contained in the
powercopy.
The following example is a simple powercopy that includes a reaction to divide a curve with a specified number of points.
The structure of this powercopy is simple. REFERENCES contains a formula curve reference to an input curve and a formula point reference
to a base point. PARAMETERS includes a single parameter for the number of divisions on the curve. PT_RESULT contains all the points
generated by the reaction. RELATIONS includes two reactions, one to update a list and one to generate new points if the PARAMETERS
geometric set is updated. Finally, MASTER_LIST is a list feature that is updated by the LIST_UPDATE reaction with a reference to each
point in PT_RESULT.
While in general a VB reaction is coded in exactly the same way as a VBA script, there are exceptions:
1) In VBA, a for...next loop often inludes the index as a suffix:
for LoopNum = 1 to 10 ... next LoopNum
In VB reactions this suffix must be omitted:
for LoopNum = 1 to 10 ... next
2) In VB reactions, if the reaction is contained in a powercopy it must reconstruct certain local information, for example the containing
geometric set and part. Since the reaction is only passed one feature or mechanicalfeature, this infomation must be reconstructed
recursively from this primary source. For example the following code returns the containing part of mechanicalfeature:
set current = MechanicalFeature
found = false
While found = false
set Current = Current.parent
If TypeName(Current) = "Part" then
found = true
end if
wend
There are also a few design considerations when coding reactions for geometry-generating powercopies.
converted by Web2PDFConvert.com
1) Always delete last in, first out. For example if a sequence of points is generated from a surface and subsequently a sequence of lines is
generated from the point sequence, when a reaction is fired to update the configuration the lines must be deleted first and then,
subsequently, the points. The specific code to delete an object is
CurrentPart.HybridShapeFactory.DeleteObjectForDatum(CurrentReference).
Example:
For LoopNum = 1 to MechanicalFeature.parent.item("PT_RESULT").hybridshapes.count
set CurrentRef = Current.CreateReferenceFromObject(MechanicalFeature.parent.item("PT_RESULT").hybridshapes.item(1))
Current.HybridShapeFactory.DeleteObjectForDatum(CurrentRef)
next
2) Always update at the object level, never at the part level. In particular one must always update an object before generating new geometry
associated to that object. The code for local update is
CurrentPart.UpdateObject(CurrentObject).
The following is the entire code, with comments, of the VB reaction hung on PT_RESULT.
Dim LoopNum as Integer
'*********************************** FIND THE CONTAINING PART *****************************
set current = MechanicalFeature
found = false
While found = false
set Current = Current.parent
If TypeName(Current) = "Part" then
found = true
end if
wend
'*********** FIND THE PARAMETER IN THE PARAMETERS SET CALLED NUM_PTS ********************
set CurrentParams = Current.Parameters.Sublist(MechanicalFeature,true)
For LoopNum = 1 to CurrentParams.count
If instr(CurrentParams.item(LoopNum).name,"NUM_PTS") then
CurrentNum = CurrentParams.item(LoopNum).value
else
end if
next
'****************************** DELETE OLD POINTS IN PT_RESULT *************************
For LoopNum = 1 to MechanicalFeature.parent.item("PT_RESULT").hybridshapes.count
set CurrentRef = Current.CreateReferenceFromObject(MechanicalFeature.parent.item("PT_RESULT").hybridshapes.item(1))
Current.HybridShapeFactory.DeleteObjectForDatum(CurrentRef)
next
'****************************** CREATE NEW POINTS IN PT_RESULT *************************
Set CurrentCurve = MechanicalFeature.Parent.Item("REFERENCE").HybridShapes.Item("CURVE")
Set CrvRef = Current.CreateReferenceFromObject(CurrentCurve)
Set ShapeFact = Current.HybridShapeFactory
For LoopNum = 1 To CurrentNum
Set hybridShapePointOnCurve1 = ShapeFact.AddNewPointOnCurveFromPercent(CrvRef, (LoopNum-1) / (CurrentNum-1), False)
hybridShapePointOnCurve1.name = "PT_" & LoopNum
MechanicalFeature.parent.item("PT_RESULT").AppendHybridShape hybridShapePointOnCurve1
Next
End sub
Media:SMARTDIVIDE.zip
Categories:
Andrew Drafts
|
Best Practices
|
Knowledgeware
|
Knowledge Templates
wiki navigation
Main Page
Create Article
Recent changes
Random page
converted by Web2PDFConvert.com
Help
resources
V1R4 Documentation
V1R3 Documentation
Gehry Technologies
search
Go
Search
toolbox
What links here
Related changes
Upload file
Special pages
Printable version
Permanent link
This page was last modified 16:22, 2 January 2008.
Content is available under
terms described in Copyrights.
About gtwiki
Disclaimers
converted by Web2PDFConvert.com
Zgłoś jeśli naruszono regulamin