Jump to content
Sign in to follow this  
VvierA

How do I get a handle to an object with a certain database record...?

Recommended Posts

Hi there,

with your help I have an idea, how to solve this problem...

but now there is the next problem:

Let's say I've an Object and the object is linked to a database.

Let's say the object has a record, for example the text record 'Billy'.

How do I get a handle to the object by using the record 'Billy'?

Thanks for any help

VvierA

Share this post


Link to post

How do I get a handle to the object by using the record 'Billy'?

You need to create a for each loop that iterates all objects types that can have this record attached. Then, you look if that record format is attached to that object.

The VS function reference has functions under "Database / Record" that give you records attached to an object, compare the name of those to your record format.

Share this post


Link to post

You need to create a for each loop that iterates all objects types that can have this record attached. Then, you look if that record format is attached to that object.

The VS function reference has functions under "Database / Record" that give you records attached to an object, compare the name of those to your record format.

Thank you hippothamus,

but is the loop really the only way? I'm not so happy about it, because loops are rather slow - I was hoping that Vectorworks could identify directly the object with the record 'Billy'.

I was hoping, that this is possible, because when you generate a list of records with a table in VW you can easily identify the referring object in the drawing by right-clicking the table entry. So Vectorworks seems to be able to 'find' objects with a record.

Thanks for further help,

VvierA

Share this post


Link to post

You need to create a for each loop that iterates all objects types that can have this record attached. Then, you look if that record format is attached to that object.

The VS function reference has functions under "Database / Record" that give you records attached to an object, compare the name of those to your record format.

Thank you hippothamus,

but is the loop really the only way? I'm not so happy about it, because loops are rather slow - I was hoping that Vectorworks could identify directly the object with the record 'Billy'.

I was hoping, that this is possible, because when you generate a list of records with a table in VW you can easily identify the referring object in the drawing by right-clicking the table entry. So Vectorworks seems to be able to 'find' objects with a record.

Thanks for further help,

VvierA

It's faster then you'd think. A handle doesn't take so much load as it's small in size.

Also, a worksheet does exactly what I described, the right click uses the handle it has on that object to select it. That handle is found by iterating all objects and looking for the criteria you provided.

Even if there was such a function, the code behind that function would do the same, iterating objects :)

Share this post


Link to post

@hippothamus

Thank you so much for the input.

I just found this:

and thought, that maybe there is some way to use the search criteria to simply get the handle to my object.

Even if VW does the loop in the background I would be more convenient, because I wouldn't need to worry about how to program the loop and make it safe for any cases (for example: user abort or very large drawings with thousands of elements etc.).

Share this post


Link to post

Yes you use your criteria in the for each function.

If you find it hard to create the criteria string, just create your "search" in a worksheet database row, then click modify and push cancel. Your string becomes visible :)

Share this post


Link to post

@hippothamus

Thanks - a good trick to get the search string.

Isn't it possible, to use such a search string in Vectorscript to get the handle to an object I am looking for globally in the drawing?

Share this post


Link to post

Sorry I could not reply earlier but it is a holiday here and I usually fix things around the house when I am off work.

The answer as I discussed in your other post is to use ForEachObject, which is a built in loop routine that looks for objects that meet some criteria.

The following will get a handle to an object with a record name 'Shape', field 'ID' = 'A1' and will change its color to red.

PROCEDURE SelA1;
VAR
targetHdl: HANDLE;

PROCEDURE ProcessObj(objHdl: HANDLE);
BEGIN
targetHdl:= objHdl;
END;
BEGIN
DSelectAll;
ForEachObject(ProcessObj,(('Shape'.'ID'='A1')));
IF targetHdl <> NIL THEN
BEGIN
SetSelect(targetHdl);
SetFillBack(targetHdl, 65535, 0, 0);
END;
END;
Run(SelA1);

The following will select all objects with the record 'Shape' attached and change their color to blue.

PROCEDURE SelShapes;
VAR
i,shpTot: INTEGER;
shapeList: DYNARRAY[] OF HANDLE;

PROCEDURE ProcessObjs(objHdl: HANDLE);
BEGIN
i:= i + 1;
shapeList[i]:= objHdl;
END;
BEGIN
shpTot:= Count(((R IN ['Shape'])));
IF shpTot > 0 THEN
BEGIN
DSelectAll;
ALLOCATE shapeList[1..shpTot];
i:= 0;
ForEachObject(ProcessObjs,((R IN ['Shape'])));
FOR i:= 1 TO shpTot DO
	BEGIN
	SetSelect(shapeList[i]);
	SetFillBack(shapeList[i], 0, 0, 65535);
	END;
END;
END;
Run(SelShapes);

The criteria builder should be the second menu item in the vs editor so you do not need to exit the editor for that.

The test file with the scripts is attached.

Share this post


Link to post

@Miguel

Very cool. Thank you so much for the work.

I hope I can do the rest for myself and don't have to bother you anymore.

All the best

Share this post


Link to post

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.

Sign in to follow this  

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...