Jump to content
Developer Wiki and Function Reference Links ×

SetName() on objects in a PIO


Hippocode

Recommended Posts

While trying to make my custom space PIO I can't manage to name the polyline inside my PIO. ( This for use of the location selection critera )

The objecthandle will name the PIO itself, but not the polyline in it, The LNewObj doesn't do anything, and the pathHd of the object can have a name, but that's useless.

am I overlooking smth ?

Link to comment

I think you can not name an object inside a PIO because when you place a second instance of your PIO, the name of your poly inside your PIO will already excist in the drawing.

with symbols, you can do such things though, because the object will only excist ones in the symbol definition.

I can be wrong, so don't shoot me if I am :) .

Link to comment
  • Vectorworks, Inc Employee

All names in the document need to be unique. You should be able to name objects within a PIO but they have to be unique in the document including names of class, symbols, textures etc.

The simplest way to do this is use GetObject() or Name2Index() to make sure the name is not in use.

Link to comment

Adding a parameter is not what I'm looking for. I need to name an object ( the polyline in this case ) so it can be used as a location.

I've been trying something and these are the non-working results.

- naming the path works

- naming the polyline doesn't work.

So I thought I didn't have the handle right. I create a text object, get a handle to it with LNewObj and name it within the script. Doesn't work either.

All I can name is the PIO itself, and the handle of the PIO. Everything else returns an empty name slot :(

Link to comment

I imagine the issue you are having is that each name must be unique or that setname worked, but you can't see that it did. PIO regen code can run a few times during insertion, so the only way to guarantee a unique name is for the code to check for one.

That said, there may be a more elegant solution than using Location and criteria. Have you looked at http://developer.vectorworks.net/index.php?title=VS:PtInPoly and http://developer.vectorworks.net/index.php?title=VS:PtInRect?

-Josh

Link to comment

Well,

The name is unique and does get checked before added, but still I can't name any objects inside a PIO besides the path of the 2d path object. With getobject I check it to return NIL ( which it does ), but it doesn't add the name to the fresh polyline. I guess its impossible then :(

Why and how I want it to work:

-space 2d object lets you make a frame for a room.

-Popup asks a roomnumber and name ( these together form the name )

-The name gets inserted in the polyline of the object ( which I can't manage)

-After that, another script will get trough all the spaces and use the name as a location criteria, so it can select all symbols in that space.

PtInPoly can't be used for it, as the PIO isn't a standalone poly.

PROCEDURE objectos;

CONST
kObjXPropSpecialEdit = 3;
kReshapeSpecialEdit = 3;
kObjXIs2DSurfaceEligible = 14;
kObjXPropEditGroup = 1;
kObjXPropEditGroupPath = 2;
kObjOnInitXProperties = 5;
kResetEventID = 3; 

VAR
   theEvent, theButton :LONGINT;
   status :BOOLEAN;

PROCEDURE Main;
VAR
pathHd,objHd,objrecHd,wHd,PHd,TempHd 	:HANDLE;
result					:BOOLEAN;
objName				:STRING;

num_vertices,i			:INTEGER;
seg_angle				:REAL;
dir_vec				:VECTOR;

v1x,v1y,v2x,v2y,mx,my		 :REAL;
t1x,t1y,t2x,t2y,tdx,tdy		:REAL;
x,y					:REAL;
vertexType :INTEGER;
vertexRadius :REAL;

ShowDN				:BOOLEAN;
positie,i_DN,FontSize		:INTEGER;

request1,request2,result1,result2,RuimteNaam,RuimteNummer:STRING;
name,klasse,temp: STRING;

BEGIN
{ retrieve plug-in object information }
result:= GetCustomObjectInfo(objName,objHd,objrecHd,wHd);

{ if the plug-in object info was successfully retrieved }
IF result THEN BEGIN

	{ retrieve the parameter settings for the object }
	RuimteNaam	:= PSPACENAME;
	RuimteNummer	:= PSPACENUMBER;

	{ Juiste klasse selecteren }
	klasse:='TDE-60 sanitair-koud';
	NameClass(klasse);

	{ obtain a handle to the path polygon of the object }
	pathHd:= GetCustomObjectPath(objHd);

	{ get the number of vertices in the path }
	num_vertices:= GetVertNum(pathHd);

	{ draw the piping lines and text label }
	BeginPoly;

	IF num_vertices = 2 THEN BEGIN
		i:=2;
		GetPolyPt(pathHd,i,v2x,v2y);
		GetPolyPt(pathHd,i - 1,v1x,v1y);
			MoveTo(v1x,v1y);
			{LineTo(v2x,v2y);}
			AddPoint(v2x,v2y);
	END;
	FOR i:= 2 TO num_vertices DO BEGIN
		GetPolyPt(pathHd,i,v2x,v2y);
		GetPolyPt(pathHd,i - 1,v1x,v1y);


		MoveTo(v1x,v1y);
		IF num_vertices <> 2 THEN AddPoint(v2x,v2y);


	END;	
	EndPoly;
END;

SetPolyClosed(LNewObj, True);

request1 := 'Geef het lokaalnummer in:';
request2 := 'Geef de ruimtenaam in:';

IF RuimteNummer = '' THEN BEGIN
	result1:=StrDialog(request1,RuimteNummer);
	SetRField(ObjHd,ObjName,'SpaceNumber',result1);
END
ELSE BEGIN
	result1:=RuimteNummer;
END;
IF RuimteNaam = '' THEN BEGIN
	result2:=StrDialog(request2,RuimteNaam);
	SetRField(ObjHd,ObjName,'SpaceName',result2);
END
ELSE BEGIN
	result2:=RuimteNaam;
END;

name:=concat(result1,': ',result2);

TempHd := GetObject(name);
 	IF TempHd  = NIL THEN BEGIN
	SetName(LNewObj,name);
	Message('object name is unique, send it to the  polyline :(');
END;

{Add Text}
HCenter(LNewObj,x,y);
{ set the text properties }
TextSize(10);
TextJust(2);
TextVerticalAlign(3);
TextOrigin(x,y);
CreateText(name);

END;

BEGIN
vsoGetEventInfo(theEvent, theButton);
CASE theEvent OF
	kObjOnInitXProperties:
	BEGIN
		status:=SetObjPropCharVS(kObjXPropSpecialEdit,Chr(kReshapeSpecialEdit));
		status:=SetObjPropVS(kObjXIs2DSurfaceEligible,TRUE);
		status:=SetObjPropCharVS(kObjXPropEditGroup,Chr(kObjXPropEditGroupPath));
		status:=vsoInsertAllParams;
	END;
	kResetEventID:
	BEGIN
		Main;
	END;
END;
END;
RUN(objectos);

Edited by hippothamus
Link to comment
-The name gets inserted in the polyline of the object ( which I can't manage)

Use a pio parameter for storing this info. Use a text object for showing the info.

PtInPoly can't be used for it, as the PIO isn't a standalone poly.

You can get the path of the pio, with that and the insertion point of the pio, you can use PtInPoly, though it can be that you have to draw the poly of the pio and then delete it afterwards.

Link to comment

You are making it more omplicated than it should. You are already half way there with the path object but asking for information from the user with a dialog when it can be entered in the OIP. Besides the dialog will show up every time the object is regenerated.

To make the code cleaner I would add a third hidden parameter to hold the full name as in:

fullName:= Concat(RuimteNummer,':',RuimteNaam);

SetRField(ObjHd,ObjName,'__HiddenField',fullName);

To find the symbols in space '301:Room Name' on a separate script:

PROCEDURE FindSyms;
VAR
spaceHdl,polyHdl: HANDLE;

PROCEDURE GetSpace(objHdl: HANDLE);
BEGIN
spaceHdl:= objHdl;
END;

PROCEDURE GetSyms(symHdl: HANDLE);
VAR
	symPt: POINT;
BEGIN
GetSymLoc(symHdl,symPt.x,symPt.y);
IF PtInPoly(symPt.x,symPt.y,polyHdl) THEN
	BEGIN
	{ Process the symbol inside the space pio further }
	.........
	.........
	END;
END;

BEGIN
ForEachObject(GetSpace,(('Pio Name'.'__HiddenField'='301:Room Name')));
IF spaceHdl <> NIL THEN
BEGIN
polyHdl:= GetCustomObjectPath(spaceHdl);

{This will get all symbols but it can be modified to limit only the ones in the active layer }
ForEachObject(GetSyms,((T=SYMBOL)));
END;
END;

This code could also be triggered by a button parameter in the OIP if desired.

Link to comment

Hey,

Thanks for the great responses.

I changed the space script with your suggestions and I tweaked your script to find symbols in a room.

I do encounter a problem comparing the coordinates though. Maybe becuase the coordinates of the path are relative to the insertion point of the space object ?

Once I get this to work I will turn around the code, so its searches all the symbols and compares them to all spaces. Because like this it checks every symbol way to many times :)

Procedure FindSymbols;
VAR
SpaceHandle,PolyHandle: 	HANDLE;
i,j:					INTEGER;
temp_string:				STRING;
p1x,p2x,p1y,p2y:			REAL;

PROCEDURE GetSpace(ObjHandle:HANDLE);

	FUNCTION GetSymbols(SymHandle:HANDLE) :BOOLEAN;
	VAR
		symPt:	POINT;
		SymbolName:	STRING;
	BEGIN
		GetSymLoc(SymHandle,symPt.x,symPt.y);
		SymbolName:=GetSymName(SymHandle);

		IF PtInPoly(symPt.x,symPt.y,PolyHandle) AND (SymbolName <>'') THEN BEGIN
			AlrtDialog(concat(SymbolName,': x=',symPt.x,' y=',symPt.y));
		END;
	END;

BEGIN
	SpaceHandle:=	ObjHandle;
	{ space found }
	IF SpaceHandle <> NIL THEN BEGIN
		{ Get the path }
		PolyHandle:=GetCustomObjectPath(SpaceHandle);
		{
		GetBBox(PolyHandle,p1x,p1y,p2x,p2y);
		Message('p1x: ',p1x,', p1y: ',p1y,' p2x: ',p2x,' p2y: ',p2y);}

		{ Only get all the objects in the current layer }
		ForEachObjectInLayer(GetSymbols,0,2,0);
	END;
END;

BEGIN
{ Loop trough each custom space object }
ForEachObject(GetSpace,((PON='TDE_Space')));
END;

Run(FindSymbols);

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