Jayme McColgan Posted August 29, 2023 Share Posted August 29, 2023 I know it's possible to create a symbol of a PIO from the menus but you think it's possible to have a button in the OIP of a point object that will export itself as a symbol into the current drawing using the "Covert to plug-in object" option. I tried calling vs.SymbolToGroup() but that just replaces the whole PIO as a group and doesn't save it to the resource browser. Quote Link to comment
Pat Stanford Posted August 30, 2023 Share Posted August 30, 2023 I have no idea if you can make this work or not, but as Vlado told me once: Quote "What you are trying to do sounds fancy, and as such it sounds like it won't work.” Vlado Stanev, VW SDK List Dec. 4, 2015 What end result are you trying to achieve and why? Perhaps we can offer a better alternative. Quote Link to comment
Jayme McColgan Posted August 30, 2023 Author Share Posted August 30, 2023 1 hour ago, Pat Stanford said: I have no idea if you can make this work or not, but as Vlado told me once: What end result are you trying to achieve and why? Perhaps we can offer a better alternative. hahaha. my Point object plugin uses parameters in the OIP to create a 3d object. I want the user to be able to save that as a symbol so it can be used in the future without having to recreate it. I know you can manually do this with the "Create Symbol" menu command and having "Convert to plug-in object" selected. I'd like to make it easier for the user by making that a button in the OIP. vs.DoMenuTextByName("Create Symbol", 0) is a workaround but doesn't select "Convert to plug-in object". both vs.DoMenuTextByName("Symbol to Group", 0) and vs.DoMenuTextByName("Shallow Symbol to Group", 0) return an error that those menu commands don't exist Quote Link to comment
Jesse Cogswell Posted August 30, 2023 Share Posted August 30, 2023 You can absolutely do this. The key here is to create an "empty" symbol (I usually use a 2D locus with a handle so I can delete it later), then use CreateDuplicateObject to duplicate the target PIO into the symbol container. Then you just need to set the Insert As Group object variable for the symbol. Below is a super simple way to do this in Vectorscript, you'll have to adapt it for Python. It will detect whether the selected object is a PIO, then ask a name for the symbol. If the symbol name doesn't conflict with an existing named object, the script will create a symbol in the Resource Manager root (you can add code of your own to determine placement), duplicate the PIO, delete the locus, and flip the Insert As Group flag. Easy-peasy. PROCEDURE ExportPIO; CONST kPIO = 86; kInsertAsGroup = 127; VAR h,pioHd,tempHd:HANDLE; symbolName:STRING; pt:POINT; BEGIN IF(GetTypeN(FSActLayer) = kPIO) THEN pioHd:=FSActLayer; IF(pioHD <> NIL) THEN BEGIN symbolName:=StrDialog('Enter symbol name',''); IF ((NOT DidCancel) & (GetObject(symbolName) = NIL)) THEN BEGIN GetSymLoc(pioHd,pt.x,pt.y); BeginSym(symbolName); Locus(0,0); tempHd:=LNewObj; EndSym; h:=CreateDuplicateObject(pioHd,GetObject(symbolName)); HMove(h,0 - pt.x,0 - pt.y); DelObject(tempHd); SetObjectVariableBoolean(GetObject(symbolName),kInsertAsGroup,TRUE); END; END; END; Run(ExportPIO); 1 Quote Link to comment
Jayme McColgan Posted November 1, 2023 Author Share Posted November 1, 2023 Here's the Python Version of this for future people. I added some error checking to make sure that symbol name doesn't already exist. Pcontinue = True ### get symbols in current cad cur_symbols = [] MyList, NumItems = vs.BuildResourceList(16, 0, '') for i in range(NumItems): MyName = vs.GetNameFromResourceList(MyList, i+1) cur_symbols.append(MyName) ### Pull Case Name case_name = str(vs.GetRField(PIO_handle, recname, "Case Name")) ### If not case Name define one if not case_name: case_name = vs.StrDialog('Enter Case name','') if vs.DidCancel() or not case_name: Pcontinue = False if Pcontinue: ### Check for unique name test = 1 main_name = case_name while case_name in cur_symbols: case_name = f"{main_name}-{test}" test += 1 x,y = vs.GetSymLoc(PIO_handle) vs.BeginSym(case_name) vs.Locus(0,0) tempHd =vs.LNewObj() vs.EndSym() h = vs.CreateDuplicateObject(PIO_handle,vs.GetObject(case_name)) vs.HMove(h,-x,-y) vs.DelObject(tempHd) vs.SetObjectVariableBoolean(vs.GetObject(case_name),127,True) Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.