Jump to content
Developer Wiki and Function Reference Links ×

duplicate objects inserted into walls w/o duplicating the walls?


Recommended Posts

Is it possible to duplicate a symbol (or a door.  or a window) inserted into a wall without duplicating the wall also? 

 

If I wasn't scripting it I would copy the symbol/door/window and then paste in place to get the symbol/door/window copied in the same location (or any location - I could always move it later I guess)

 

 

Thanks!

Link to comment

So why not do the copy paste in the script. It seems to work. If you want the new object to be In Wall, just use a SetParent.

 

    DoMenuTextByName('Copy',0);
    DoMenuTextByName('Paste in Place',0);    

 

Just so you don't feel too bad, I just spent 45 minutes coming to this realization. ;-)

Link to comment

Hi Pat,

   Don't make me laugh  (too late).  

 

   When I read Michael's second post this morning, I thought, "better" way?!?  What's wrong with Copy / Paste? I've been using it since 1990 and it's never let me down. And before you threw my name onto the Coliseum Floor, I thought maybe hDuplicate() would work, so I tried it on a single window in a wall. It seemed simpler, but it wasn't working. Nope, this wasn't better, and real work got in the way, so I shelved it. 

 

   After reading your second post (and laughing) I recreated the file and tried it again. The duplicate and the original windows seem to lock themselves to each other when hDuplicate() is used. I can't drag the duplicate window around after I create it. The new window doesn't cut the wall properly in Plan, though the OIP says it is a "Window In Wall". Lastly, I can't delete it. Select it, yes; delete it, no. If I delete the original window, then both delete – very odd. They seem joined at the hip. Perhaps this is a bug. I don't know if hDuplicate should work on Windows in Walls. Naively, I think it should. I'll send it in and see what comes back.

 

   So, after spending more than an hour pushing dead code around, I tried your approach — Copy / Paste (in Place). It works like a champ. The two windows act as separate entities, interactively and programatically. I'm giving your approach 2-thumbs-up.

 

   Michael, do what Pat says. He's usually right*. ;-)

 

Raymond

 

* When he's finished his morning coffee, he flies back from Columbia (Maryland).

He never has to launder his bed linens, he just creates new spreadsheets.

When asked to solve vector problems, he is never wrong, and his answers always follow the Right–Hand–Rule.

He IS the Most Interesting Man On The Forum!

  • Like 1
Link to comment

@bcd Nothing to be sorry about. You actually hit on the answer.  With the Wall Insertion Mode off, the Duplicate works as Michael, Raymond and I wanted it to.

 

DOH!

 

Great solution.

 

Procedure Test;

Var	H1, H2: Handle;
	B1: Boolean;

Begin
	B1:=GetPref(581);
	SetPref(581, False);
	H1:=FSActLayer;
	H2:=CreateDuplicateObject(H1, ActLayer);
	HMove(H2,60",60");
	SetPref(581,B1);
End;

Run(Test);

 

Link to comment

OK.  More questions.

 

Pat. That script isn't working for me.  Just tried it in a blank file.  Created a wall.  Stuck a window in it.  Selected the window and ran the script.

 

It duplicated the wall with the window in it.

 

Problem 2.  

 

Your idea of using DoTextByName does work if I select a window in a wall.  But a ForEachObject with the criteria being Type is window won't select the window.  It doesn't seem to select anything.

 

Any more ideas?

 

 

Link to comment

Just chiming in, I started with Vectorscript but have moved on to Python, as it's much easier -for me- to learn and use. Hopefully this is ok here, I guess you could convert it to VS if needed.

 

Below is a script in python:

import vs
# copy symbol/plugin out of wall
# As Pat said earlier, spaces/tabs are important in python
# I always use an external editor to check for this before pasting my code back into vectorworks
# I use PyCharm Community Edition

def list_objs_inserted(h_wall):
    h_obj = vs.FIn3D(h_wall)
    list_objsinserted = []

    while h_obj != None:
        if vs.GetTypeN(h_obj) in [86, 15]:
            list_objsinserted.append(h_obj)
        h_obj = vs.NextObj(h_obj)

    return list_objsinserted

# A Wall needs to be selected!
h2_wall = vs.FSActLayer()
vs.SetDSelect(h2_wall)

objs_in_wall = list_objs_inserted(h2_wall)

for obj in objs_in_wall:
    newObj = vs.CreateDuplicateObject(obj, None) 
    # None passed in as last parameter just places a copy on the layer you're on
    
    vs.SetSelect(newObj)

 

Got the idea from @orso b. schmid's website here : http://www.vectorlab.info/index.php?title=Han-First_Selected_in_Active_Container

That website is an invaluable resource for vectorworks vs/python coders

 

HTH
Tui

Link to comment

DING DING DING!!! We Have A Winner!!!  Thanks, Tui!

 

Put  door in a wall and select the door and run the following script   

 

Message(GetTypeN(FSActLayer));

 

For me it returns object type 68 = Wall.  That expands why the CreateDuplicateObject is duplicating the complete wall.

 

So now we just need to use Tui (and C's) Fin3D Trick to get the objects. The following works to duplicate every PIO in a wall. It is left to the reader to figure out how to filter out the objects that should not be duplicated.

 

Procedure Test;

Var
	H1,H2,H3:	Handle;
	
Begin
	H1:=FSActLayer;
	SetDSelect(H1);
	H2:=FIn3D(H1);
	While H2 <> Nil do
		Begin
			If GetTypeN(H2)=86 then H3:=CreateDuplicateObject(H2,Nil);
			HMove(H3, 60",60");
			H2:=NextObj(H2);
		End;
End;

Run(Test);
		

 

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...