The following example explains how to generate a design variant with script. This function is currently not fully available.
The starting point for the variant is two flanges from two sheet parts. One flange is to be added to each so that the two flanges touch in a surface and can be bolted. The two flanges are added so that they lie in the angle bisector between the two initial flanges.
Step 1: Construction
(see Example of a Design Variant in Sheet Metal Processing)
Step 2: Parameterise 1st Part
The parameters of the design variant need to be defined as variables for the design variant base body:
Activate the base sheet and choose the Formula for processed part function. Enter the part_of_edge(edge1) formula or part_of_edge(edge2) for the 2nd base sheet.
Step 3: Insert new Script execution feature step
It is possible to insert into the feature list a Visual Basic Script (VBS) in which you have access to the variables of the calculated part, can calculate values using the resources of Basic and a COM interface to HiCAD and can assign variables. You can then use these variables in the formulas of subsequent features.
The script is inserted before the feature in whose context menu you are located.
Script | Description |
---|---|
set partVariables = CreateObject ("HicadNext.Variables") |
In VBS, objects made available by a COM server need to be created with 'CreateObject'. |
set variantVariables = CreateObject ("HicadNext.Variables") |
|
set c = CreateObject ("Hicad-Next.Const") |
|
partVariables.MakeCurrentVars() 'the variables of the part |
'MakeCurrentVars' provides access to the variables of the part that has just been calculated. 'MakeVariantVars': A design variant creates a design variant feature in all parts of the drawing that are being processed or created. These features work on a common data record to which, for example, the parameter variables of the variant, and only these parameter variables, belong. The variant variables allow you to note information for calculating other parts when calculating one part. |
variantVariables.MakeVariantVars() 'local variables of the variant |
|
ownIndex = "1" |
The scripts in the two parts differ only at this point. |
otherIndex = "2" |
|
'The edge to which the flange is added |
Here, edge objects are generated for the two parameter edges of the variant and assigned variable values. |
set ownEdge = CreateObject ("HicadNext.Edge") |
|
call partVariables.GetEdgeVar ("edge"+ownIndex, ownEdge) |
|
'The edge in the other part |
|
set otherEdge = CreateObject ("HicadNext.Edge") |
|
call partVariables.GetEdgeVar ("edge"+otherIndex, otherEdge) |
|
'determine 1st facet from the edge |
Determining the top flange facet belonging to the edge in the current part |
set ownFace= CreateObject ("HicadNext.Face") |
|
'1st flange |
|
set ownSheet = CreateObject ("HicadNext.Sheet") |
An object of type 'Sheet' represents a flange with a marked facet which is produced on the edge specified during construction of the object. |
call ownSheet.Construct (ownEdge) |
|
'1st top facet call ownSheet.GetFace(ownFace) |
|
'determine 2nd facet (either from the edge or the marked facet) |
Determining the top flange facet belonging to the edge in the other part: If the other part has already been calculated, the edge to which the flange is added in the other part is no longer available. You then take the top facet of the other flange from the variant variables, where it was saved when the script of the other part was executed. |
set otherFace= CreateObject ("HicadNext.Face") |
|
if (otherEdge.index = 0) then call variantVari-ables.GetFaceVar("reference facet"+otherIndex, otherFace) 'msgbox "reference facet"+otherIndex+" "+cstr(otherFace) |
|
else '2nd flange set otherSheet = CreateObject ("HicadNext.Sheet") call otherSheet.Construct (otherEdge) |
|
'2nd top facet call otherSheet.GetFace(otherFace) |
|
end if |
|
'The angle between the flanges |
You can now calculate the angle between the facets |
sheetAngle = 180-ownFace.Angle (otherFace) |
|
'sheet shortening thickness = ownSheet.GetThickness() radius = partVariables.GetRealVar ("bend radius") |
The shortening is calculated from sheet thickness and bend radius and the angle between the sheets. Note that VBS works with angles in radians. |
beta= sheetAngle/2 betaRad = beta*(c.Pi()/180) d = (thickness+radius) * tan betaRad/2) |
|
'Data for the screw assembly edgeLength = ownEdge.GetLength() |
Calculation of the data for the screw assembly: The calculation must be performed before adding, as the edge whose length is needed will otherwise no longer be available. |
outerDist = 30 maxDist = 40 |
|
dist1 = edgeLength-2*outerDist count = round (dist1/maxDist + 0.5) if (count <= 1) then dist = 0 |
|
else dist = dist1/(count-1) end if |
|
'write variables to the Hicad variables |
Setting the variables in HiCAD. |
call partVariables.SetRealVar ("number", count) call partVariables.SetRealVar ("distance", dist) call partVariables.SetRealVar ("angle", sheetAngle/2) call partVariables.SetRealVar ("shortening", d) call variantVariables.SetFaceVar ("reference facet"+ownIndex, ownFace) |
You can simply copy the script for the second part and swap the two strings "1" and "2" at the beginning.
You can edit the script of a script feature by double-clicking the feature.
Please keep in mind, at this point, the Advice on Part Variables and Log Variables
Step 4: Fitting the Variant
Once the variants have been fitted, the two sheet parts each have a design variant feature.
© Copyright 1994-2018, ISD Software und Systeme GmbH |