Hallo
I managed to write a python script in script palette for this function (converting multiple user selected objects to one 2D symbol) . I have two questions:
1. the newly created symbol is not placed in the center of the new object !!!
2. how do I export and share the script .py file with other users so that they import it from server and use it?
Thank you
# written by NNT 27.9.2023
import vs;
objs = []
def GetBBoxCenter (h):
box = vs.GetBBox(h)
topL2D = box[0]
botR2D = box[1]
center = [None, None]
BB_width = botR2D[0] - topL2D[0]
BB_height = topL2D[1] - botR2D[1]
center[0] = topL2D[0] + BB_width / 2
center[1] = topL2D[1] - BB_height / 2
center = tuple (center)
return (center, BB_width)
def collect(handle):
objs.append(handle)
# collect visible selected objects
vs.ForEachObject(collect, '((VSEL=TRUE))')
vs.AlrtDialog('Anzahl der ausgewählten Objekte: {}'.format(len(objs)))
# create new Symbol in Document
newSymNameDefault = 'YourNewSymbol'
newSymName = vs.StrDialog("Neues Symbol Name",newSymNameDefault)
vs.SetOriginAbsolute(0,0,0)
vs.BeginSym(newSymName)
vs.Locus(0,0,0)
h = vs.LNewObj()
vs.EndSym()
h_sym = vs.GetObject(newSymName)
# add/set first obj to symbol
objSym = objs[0]
vs.SetPlanarRef(objSym, 0) # 0 is ref ID for Screen plane
vs.SetParent(objSym, h_sym)
vs.ResetObject(objSym)
vs.ResetObject(h_sym)
vs.Set2DComponentGroup(h_sym, objSym, 10) # this command works for screen plane objects only
# replace all selected objs with new symbol
# get original symbol obj center and width for rotation angle comparison
objSymCenter, objSymWidth = GetBBoxCenter(objSym)
for i,obj in enumerate(objs):
objCenter, objWidth = GetBBoxCenter(obj)
rotAngle = 0
if objWidth != objSymWidth:
rotAngle = 90
newSym = vs.Symbol(newSymName, objCenter, rotAngle)
vs.ResetObject(obj)
vs.ResetObject(newSym)
vs.DelObject(obj)
vs.AlrtDialog('Symbol "{}" ist in Zubehör Manager'.format(newSymName))