Jump to content
Developer Wiki and Function Reference Links ×

Duplicate Symbol Script


MTRobin

Recommended Posts

Hi Everyone,

 

If I have a symbol in my workspace selected I would like to have a script that duplicates that symbol in the resource manager and replaces the selected symbol with the new, duplicated, one. Can someone please help me with this?

 

Thank you

 

Maxwell

Link to comment

Here's one I wrote years ago. It doesn't do exactly what you want, but may be it's a start.

 

{ 20150713 - First written. }

procedure Main { Copy_to_New_Symbol };
var
h1, hL, hG : handle;
N : string;

{••••••• PROGRAM ••••••••}
begin
ClrMessage;
DSelectObj (T <> Symbol);
if (Count (Sel = True) = 1) then
  begin
  h1 := FSActLayer;
  DSelectAll;
  SetSelect (h1);
  Message ('Original Symbol Name : ', GetSymName (h1));
  Duplicate (50, 50);
  hL := LSActLayer;
  SetDSelect (h1);
  SymbolToGroup (hL, 0);
  hG := FSActLayer;
  HUngroup (hG);
  DoMenuTextByName ('Create Symbol', 0);
  DeleteObjs;
  hL := LObject;
  N := GetName (hL);
  SetActSymbol (N);
  SetTool (-209); { or -309 for 3D symbols }
  hL := LSActLayer;
  if (YNDialog ('Do you want to delete the original symbol ?') = True) then
    DelObject (h1);
  end
else
  AlrtDialog ('No Symbol Selected On This Layer !');
ClrMessage;
end;
run (Main);

 

Link to comment

Thanks for this! It really helped. Here is what I came up with. It duplicates the selected symbol and creates it as a new, unique, one. The same way the "Make Unique" feature works in Sketchup. Do you know how I can bypass the pop up symbol settings prompt and the folder location prompt when creating a new symbol? I'd like to have this script run without any input from the user.

 

PROCEDURE MakeUnique;

VAR
Selection : HANDLE;

BEGIN
    Selection := FSActLayer;
    Duplicate(0,0);
    DelObject(Selection);
    Selection := FSActLayer;
    SymbolToGroup(Selection,0);
    Ungroup;
    DoMenuTextByName('Create Symbol', 0)
END;
Run(MakeUnique);

 

Thanks

 

Maxwell

Link to comment
34 minutes ago, MullinRJ said:

Instead of using DoMenuTextByName(), use BeginSym() and EndSym calls before and after your duplication code, respectively.

 

Raymond

Is there a way to have it leave the instance in place? Really all I need i is the symbol to duplicate with a new unique name and remain in the workspace.

 

Thanks

 

Max

Edited by MTRobin
Link to comment

Hi Max,

   There is no need to duplicate a symbol instance to decompose a copy of it. Just decompose the original instance inside BeginSym() and EndSym, giving it a new name. To avoid problems later, it is best to do all your dirty work at the origin. Move symbol to (0, 0) and unrotate before demo and rebuild. To leave an instance in place, place the new symbol at the same XY/Rot as the original symbol when you are done. Here a minimized script to do just that.

PROCEDURE MakeUnique;
VAR
	Selection : HANDLE;
	X, Y, Rot :Real;
BEGIN
	Selection := FSActLayer;	{ get handle to Sym }

	GetSymLoc(Selection, X, Y);	{ get insertion point }
	Rot := hAngle(Selection);	{ get rotation }
	
	hMove(Selection, -X, -Y);	{ movet to origin }
	hRotate(Selection, 0, 0, -Rot);	{ unrotate }
	
	BeginSym('Sym New');
		SymbolToGroup(Selection, 0);
		if (GetTypeN(LActLayer) = 11) then Ungroup;
	EndSym;
	Symbol('Sym New', X, Y, Rot);	{ place new symbol on drawing }
    
	Sysbeep;	{ make noise when done }
END;
Run(MakeUnique);

 

HTH,

Raymond

 

Link to comment

This works, but a few things I am noticing.

 

1. I have objects in 3D and they are not staying in their proper 3D location.

2. When it creates a new symbol with the name 'New Sym' it overwrites the old one instead of adding a '2' to the end of it.

 

Thanks

 

Maxwell

Link to comment

Hi Max,

   As I said, it is a "minimized" script. I must leave something for you to do  ;-).  Do you have the Script Reference handy? There are similar calls for 3D Symbol queries, and the naming of new symbols is very subjective. If you don't want the script to rewrite an existing one, then you will have to search for the existence of the new name. If you find it you will have to increment or change yours accordingly then check again, but there are many ways to approach this. Be creative.

 

   Gotta run now. If you have more questions post again. Heck, @PatStanford hasn't even weighed in on this. If he does you'll get another load of advice to follow.

 

I'll check back later,

Raymond

Link to comment

OK, since @MullinRJ shamed me into this, I will go back to one of my standard lines:

 

I understand WHAT you want to the  script to do. What I don't understand is WHY you want to script to do it.

 

Please explain what you are trying to accomplish and we can often provide a better solution than the WHAT you are asking about. If learning to script is the WHY, then that is great and we will be ready to help. But if it is something else, there may be another way to get what you want (but if you try sometimes, you just may find, you get what you need.) 😉 

  • Like 1
Link to comment

Hi Pat,

 

Sketchup has a feature called "Make Unique" where you select a symbol and it duplicates it in place, but as a new unique symbol, replacing the old one. I am trying to do that.

 

Right now VWX doesn't have a feature like this so the long way is to duplicate the symbol in the Resource Browser, then replace the old symbol with the new symbol. I am just trying to automate that.

 

Why am I doing this? Often times I have a bunch of symbols in a drawing and I want to make one of them slightly different and then duplicate it.

 

I work primarily in 3D.

 

Thanks

 

Maxwell

  • Like 1
Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...