Jump to content

point 2d to point 3d


Recommended Posts

Thanks for the method

So this morning I tried (with my little knowledge) by using the marionette nodes and their scripts.

On my test file I put 4 points and used object by criteria node, set selection, get location. I made lists to see the result and use "is locus" to find out that 17 is 2d and 9 is 3d

objType = vs.GetTypeN(h)

 

            b = ((objType == 17) or (objType == 9)).

In the marionette script if I use the delete node, I can remove all my 2d point (locus) but how do I insert the 3d points ?

Capture d’écran 2021-09-02 à 11.35.19.png

Link to comment

@the frog Wrote up a quick script for you in Vectorscript.  It brings up a dialog asking for a Z Height, then replaces selected 2D Locus Points with 3D Locus Points at the given height.  Let me know if you have any questions about getting this script into Vectorworks as either an instance in a script palette (per drawing) or permanently into your workspace.

 

PROCEDURE Convert2DLocusTo3D;

{*	Converts selected 2D Locus Points to 3D Locus Points at given Z height
	Developed By: Jesse Cogswell
	VW Version: 2019
	Date: 9/2/2021
*}

VAR

	height:REAL;
	locusCount:INTEGER;
	heightStr:STRING;
	
PROCEDURE ConvertLocus(h:HANDLE);

{Pulls location and class data of given 2D Locus and replaces it with a 3D Locus Point}

	VAR
	
		A:POINT3D;
		class:STRING;

	BEGIN
		locusCount:=locusCount+1;
		
		GetLocPt(h,A.x,A.y);
		A.z:=height;
		class:=GetClass(h);
		
		Locus3D(A.x,A.y,A.z);
		SetClass(LNewObj,class);
		
		DelObject(h);
	END;

BEGIN
	locusCount:=0;
	
	heightStr:=StrDialog('Enter Z Height','0');
	
	IF(ValidNumStr(heightStr,height)=TRUE) THEN
		BEGIN	
			ForEachObject(ConvertLocus,(SEL=TRUE & (T=LOCUS)));
			
			IF(locusCount=0) THEN AlertInform('No 2D Locus Points Selected','',FALSE);
		END
	ELSE AlertInform('Please Enter a Valid Height','',FALSE);
END;

Run(Convert2DLocusTo3D);

 

Link to comment

Thank you for the script

No pb to insert in in a plug in but…

I am getting strange result. First it erases all the other objects in the file (only one layer). I assume the h is valid for the other objects and not only the locus.

Second it introduces in the center (0,0) new 3d points as many as the number of deleted objects and last, all the locus are not converted.

Trying on my side based on your script...

Link to comment

Ah, missed a parenthesis around SEL=TRUE in the ForEachObject criteria.  That's what I get for testing it with a file of only locus points.  Fixed code below.  I also added a check so that it will only work on selected locus points on the active layer, so you won't accidentally convert locus points selected on a non-visible layer, or a visible layer with Layer Options set to Show/Snap Others.

 

PROCEDURE Convert2DLocusTo3D;

{*	Converts selected 2D Locus Points to 3D Locus Points at given Z height
	Developed By: Jesse Cogswell
	VW Version: 2019
	Date: 9/2/2021
*}

VAR

	height:REAL;
	locusCount:INTEGER;
	heightStr,currentLayer:STRING;
	
PROCEDURE ConvertLocus(h:HANDLE);

{Pulls location and class data of given 2D Locus Point and replaces it with a 3D Locus Point}

	VAR
	
		A:POINT3D;
		class:STRING;

	BEGIN
		locusCount:=locusCount+1;
		
		GetLocPt(h,A.x,A.y);
		A.z:=height;
		class:=GetClass(h);
		
		Locus3D(A.x,A.y,A.z);
		SetClass(LNewObj,class);
		
		DelObject(h);
	END;

BEGIN
	locusCount:=0;
	
	heightStr:=StrDialog('Enter Z Height','0');
	currentLayer:=GetLName(ActLayer);
	
	IF(ValidNumStr(heightStr,height)=TRUE) THEN
		BEGIN	
			ForEachObject(ConvertLocus,((SEL=TRUE) & (T=LOCUS) & (L=currentLayer)));
			
			IF(locusCount=0) THEN AlertInform('No 2D Locus Points Selected','',FALSE);
		END
	ELSE AlertInform('Please Enter a Valid Height','',FALSE);
END;

Run(Convert2DLocusTo3D);

 

Link to comment

THANK YOU

it works and I improved my knoledge about variables. 😞 I didn't see the missing (

The next step is to transform this script in a Marionette node. "convert 2d points to 3d"

Crazy the amount of received plans where you have to convert 2d points to place them at the right high.

  • Like 1
Link to comment

I'm going to be honest here, I am not a huge fan of Marionette.  I find it clunky and slow and far less powerful than writing scripts.  The only advantage it has over scripting is the ability to have a Plug-in Object exist entirely within a drawing, allowing users to have custom parametric objects without having to share and install plug-ins.  That being said, it is much more approachable than scripting if you don't have coding experience.

 

I played around with replicating my script using just vanilla Marionette nodes and was able to get it pretty close.  The only thing I wasn't able to solve is that it groups all of the 3D Locus points together, and I was not able to find a way to ungroup them without manually doing it after running the script.

 

The Marionette you started above can be simplified.  There's no need to mess with the List or Set Select nodes as the Objs by Crit node will automatically produce a list of all objects meeting the criteria.  From there, you need a Delete node to delete the source 2D Locus Points, and a Get Location to pull the X and Y coordinates as a Point 2D.  The Locus node will build either a 2D Locus Point or a 3D Locus Point depending on what kind of point is given as an input, so you can use a Get XY node to pull apart the data from the Get Location node, adding an additional Real input node with a Point 3D node to get the requisite 3D point to force the Locus node to generate a 3D Locus Point.  A Get Class and Set Class node will match the class of the source Locus Point.

 

Now, this will convert EVERY 2D locus point in the drawing that is not embedded in a symbol or plug-in object to be converted to a 3D locus point, and all on the active layer.

 

So if you want to fully replicate my script from up above (and only convert selected 2D Locus Points), you have to wrap the network and convert it to a menu command, since selecting the network or the wrapper will deselect the Locus Points.  There are a couple of issues, as the whole network has to be run as part of creating the wrapper, and you will get an error with the Get Location node for having an empty list on the input.  So you'll need to add a Valve node to execute the network only if the list is not empty.

 

My test document is attached (in VW2021 format).

 

image.thumb.png.834e819d6eef3f2763cf9f0a886ad2dc.png

 

 

Convert 2D Locus Marionette.vwx

Link to comment
  • 1 month later...

I'm so frustrated with the instability of Marionette, that I find myself looking in these Vectorscript and Python forums, though I don't know what the difference between the two is or which might be best for creating parametric objects (or plugins?).  I think Python is used for Marionette?  I like the "approachable" graphical interface of Marionette - the colorful nodes and connecting 'em with wires is fun - along with its ability to (sometimes) create extremely useful objects.  But if only it worked more often than not...

Link to comment

The original language for "scripting" Vectorworks (Minicad) was MiniPascal. It was a VW/MC specific version of Pascal which was a popular computer language back in the 1980s.Later this was renamed "Vectorscript"

 

About a decade (??) ago, Python was grafted onto the same "hooks" used by Vectorscript. In fact, most of the Python VW functions are the same as the Vectorscript.

 

If you want to draw a line from the current location in VS the function is LineTo(X,Y), in Python the function is vs.LineTo(p1);

 

In the guts of drawing things in VW, there is no difference in abilities between the two languages. If you want to do more complicated things, then Python wins. There are many libraries that can be added to Python to "easily" do many calculations you would not want to try and write in VS. There are libraries to "easily" download data which you can then use to control what you draw.

 

You are correct that the internal language of Marionette is Python. If you have no Pascal experience, then that would be the language to start with.

 

If you are a stubborn old-timer like me, who has been writing pascal since about 1985, then you should stick to VS, and continually bitch about Python. Especially about how anyone in their right mind could possibly write and popularize a language that is "white space delimited" and allows you to completely break a program by accidentally adding or deleting a space so that the indentation of every line of the program is not absolutely perfect. 😉

  • Like 2
Link to comment

Thank you Pat, that is all very helpful.  I've been looking at Vectorscript out of a fear that Marionette's issues stem from Python.  But maybe it's safe to say that they don't, and that Marionette is dysfunctional on its own?  I've heard of Pascal before (and there you have a synopsis of my experience with it...).  Not sure I really followed your last paragraph; it sounds like Python isn't perfect, but I will check it out.  Thanks!  -Will

Link to comment

Do I need to download the Python software / "interpreter" and Mu, or are these functions provided via Vectorworks' Script Editor?  It looks like Python code lines start with " >>> " where in Vectorworks they don't and/or they starts with " vs. "?  I guess the question is, do I want to learn Python within Vectorworks, or through the Python website?  Thanks!   

Link to comment

If you are only planning to use Python in VW, then I would stick mainly to VW.  The learning tools for the basics of the Python language in VW are minimal, so you will have to do some web searches and adaptations to figure out what you need to use inside VW.

 

The Python complier is "built-in" to VW, so you don't need anything other that the ScriptEditor to make scripts run inside VW.

Link to comment

Okay, thanks.  Sadly, I've had no luck searching the web for tutorials on Vectorworks Python.  I wish Marionette would just work.  A network that I've been working on runs fine, even when wrapped, but crashes Vectorworks when I go to convert it to an object node.  I feel like whichever way I turn there's a dead end: Marionette is dysfunctional, and it looks like scripting will require a tremendous investment time-wise to learn (which I wouldn't mind if it weren't for the financial implications, especially after having already invested so much in Marionette).  But I digress!...  Thank you Pat for your feedback; I appreciate it.

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