Component naming loop using TCL
I am using tcl script to import two geometrical models (STEP)
This is my script
*start_batch_import 3
*geomimport "step_ct" "Filepath" "AttributesAsMetadata=on" "BodyIDAsMetadata=off" "CleanupTol=-0.01" "ColorsAsMetadata=off" "CreationType=Parts" "DegSurfTol=0.0" "DensityAsMetadata=off" "DisplayRepresentation=off" "DoNotMergeEdges=off" "FullNameAsMetadata=off" "ImportBlanked=off" "ImportCoordinateSystems=on" "ImportFreeCurves=on" "ImportFreePoints=on" "LayerAsMetadata=off" "LegacyHierarchyAsMetadata=off" "MID=MaterialId" "MaterialName=Material" "MeshFlag=MeshFlag" "OriginalIdAsMetadata=on" "PID=PID" "PartName=PartName" "PartNumber=PartNumber" "Revision=Revision" "ScaleFactor=1.0" "SkipCreationOfSolid=off" "SplitComponents=Part" "StitchingAcrossBodies=on" "TagsAsMetadata=on" "TargetUnits=CAD units" "ThicknessName=Thickness" "UID=UID" "VariantCondition=VariantCondition" "VariantScope=VariantScope"
*end_batch_import
*clearmark modules 1
*clearmark modules 1
*start_batch_import 3
*geomimport "step_ct" "Filepath" "AttributesAsMetadata=on" "BodyIDAsMetadata=off" "CleanupTol=-0.01" "ColorsAsMetadata=off" "CreationType=Parts" "DegSurfTol=0.0" "DensityAsMetadata=off" "DisplayRepresentation=off" "DoNotMergeEdges=off" "FullNameAsMetadata=off" "ImportBlanked=off" "ImportCoordinateSystems=on" "ImportFreeCurves=on" "ImportFreePoints=on" "LayerAsMetadata=off" "LegacyHierarchyAsMetadata=off" "MID=MaterialId" "MaterialName=Material" "MeshFlag=MeshFlag" "OriginalIdAsMetadata=on" "PID=PID" "PartName=PartName" "PartNumber=PartNumber" "Revision=Revision" "ScaleFactor=1.0" "SkipCreationOfSolid=off" "SplitComponents=Body" "StitchingAcrossBodies=on" "TagsAsMetadata=on" "TargetUnits=CAD units" "ThicknessName=Thickness" "UID=UID" "VariantCondition=VariantCondition" "VariantScope=VariantScope"
*end_batch_import
*clearmark modules 1
*clearmark modules 1
*clearmark modules 1
In the first import I am using "SplitComponents=Part", so all the surfaces will be under a single component. I used a script to name this component under ID "1" and component name "User defined". But in the second import, "SplitComponents=Part" is used and I would have lots of components from this import. I want to create a naming for the components starting with "Component 2" to "Component1", how do I do it?
I tried this script but its not working
# Create a mark for all components
*createmark comps 1 "all"
# Count the components
set num_components [*markcount comps 1]
# Start numbering from 2
for {set i 2} {$i <= $num_components + 1} {incr i} {
# Get the component ID for the current component
set comp_id [hm_entityid components $i]
# Set the new name as "Component <i>"
set new_name "Component $i"
*renameentity comps $comp_id $new_name
# Set the new ID for the component
*setvalue comps id=$comp_id id=$i
}
Answers
-
Hello @Prathveraj Shetty ,
here are few recommendations:
# Count the components
set num_components [*markcount comps 1]
# Start numbering from 2
for {set i 2} {$i <= $num_components + 1} {incr i} {
...
}is not recommended, especially for performance reasons. Please use instead
*createmark comps 1 "all"
set CompIncr 1
foreach Comp [hm_getmark comps 1] {
*setvalue comps id=$Comp name="Component$CompIncr"
incr CompIncr
}Best Regards,
Michael
0