michaelk

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

19 posts in this topic

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!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

O.o:)

 

… because I thought there MUST be another (better) way to do it!

Share this post


Link to post
Share on other sites

Turn off the wall insertion mode of the Selection tool & Alt drag

 

 

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites
15 minutes ago, MullinRJ said:

 

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

 

 

Hey Raymond

 

I always do!

 

 

Share this post


Link to post
Share on other sites

I don't always Vectorscript, but when I don't that Python white space makes me cranky.  Code Responsibly my Friend.

Share this post


Link to post
Share on other sites
19 hours ago, bcd said:

Turn off the wall insertion mode of the Selection tool & Alt drag

Aha - didn't notice this was in the Vectorsript forum. my bad.

Share this post


Link to post
Share on other sites

@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);

 

Share this post


Link to post
Share on other sites

That's why this forum is so fun.

 

Thanks Brian, Pat, & Raymond!

Share this post


Link to post
Share on other sites

That's why I try to read everything on the board. You never know when an idea from somewhere totally different will make a huge difference to what you are doing.

 

 

Share this post


Link to post
Share on other sites

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?

 

 

Share this post


Link to post
Share on other sites

I don't know what happened. It worked when I wrote and tested it. 

 

When I downloaded it after you said it didn't work I couldn't get it to work either. I will try later to see if I can figure out what is different.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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);
		

 

Share this post


Link to post
Share on other sites

Thanks Tui & Pat!

 

I had been reading about parent objects.  This makes it really much more clear!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now