Skip to content

Instantly share code, notes, and snippets.

@sheetd
Last active October 24, 2017 19:30
Show Gist options
  • Save sheetd/744b06363455d7441ed89a880afdadc9 to your computer and use it in GitHub Desktop.
Save sheetd/744b06363455d7441ed89a880afdadc9 to your computer and use it in GitHub Desktop.
// Searches for string in tree, then renames all parts/shapes/drawings to new value
let root (VPMReference )
let allInstances(List)
let vpmInst (VPMInstance )
let shapeRep (VPMRepInstance )
let dwg (Drawing )
let newInstanceName, newDwgName, new3DShapeName (String)
let toReplace = "<REPLACE>"
let replacing = "XXX"
//get assembly root
root = GetEditorRoots ("VPMReference").GetItem(1): VPMReference
//get a list of instances in assembly whose reference name includes the toReplace String-- the search result for which is not -1
allInstances = root.Query("VPMInstance" , "x.Reference.Name().Search(\""+toReplace+"\")<>-1")
Notify("Renaming features: ", allInstances .Size())
for vpmInst inside allInstances {
//find the 3D Shape and do not pass any conditions--Find returns the first item. This is faster than query since we know that is only one 3D Shape in the parts of this assembly.
shapeRep = vpmInst.Find("VPMRepInstance" , "", true)
//find the drawing.
dwg = vpmInst.Find("Drawing" , "", true)
//generate new names.
newInstanceName = ReplaceSubText(vpmInst.Reference.Name(), toReplace, replacing)
new3DShapeName = ReplaceSubText(shapeRep.Reference.Name(), toReplace, replacing)
newDwgName = ReplaceSubText(dwg.Name(), toReplace, replacing)
//set new names
vpmInst.Reference.SetAttributeString("Name", newInstanceName)
shapeRep.Reference.SetAttributeString("Name", new3DShapeName)
dwg.SetAttributeString("Name", newDwgName)
}
/*
-----------------ALTERNATE SCRIPT---------------------
let shapeRep(VPMRepReference )
let dwg(Drawing )
let root(VPMReference )
let allShapes, allDrawings(List)
let newDwgName, new3DShapeName(String)
let toReplace = "XXX"
let replacing = "WPC_MGM_WP2_M03"
//get assembly root
root = GetEditorRoots ("VPMReference").GetItem(1): VPMReference
//get a list of instances in assembly whose reference name includes the toReplace String-- the search result for which is not -1
allShapes = root.Query("VPMRepReference" , "x.Name().Search(\""+toReplace+"\")<>-1")
allDrawings = root.Query("Drawing" , "x.Name().Search(\""+toReplace+"\")<>-1")
for dwg inside allDrawings{
newDwgName = ReplaceSubText(dwg.Name(), toReplace, replacing)
dwg.SetAttributeString("Name", newDwgName)
}
let curName(String)
for shapeRep inside allShapes{
curName = shapeRep.Name
new3DShapeName = ReplaceSubText(curName, toReplace, replacing)
shapeRep.SetAttributeString("V_Name", new3DShapeName)
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment