Jump to content
Sign in to follow this  
VvierA

I'd like to associate or 'link' one object with another - any ideas?

Recommended Posts

Hello,

I'd like to write a script to link to objects to one another.

For example associate a symbol to a rectangle.

The purpose is to get a handle to the other object, when modifying the other.

Is there a way?

Thanks for any help,

VvierA

P.S.

I already found 'AddAssociation'

but this doesn't seem to give me a handle. It just links to objects so that one element is deleted/ reset if the other one is deleted/ reset.

Share this post


Link to post
Hello,

I'd like to write a script to link to objects to one another.

For example associate a symbol to a rectangle.

The purpose is to get a handle to the other object, when modifying the other.

Is there a way?

Thanks for any help,

VvierA

P.S.

I already found 'AddAssociation'

but this doesn't seem to give me a handle. It just links to objects so that one element is deleted/ reset if the other one is deleted/ reset.

Yes, the association is just used when deleting them. Nothing more.

What you request is only possible with custom made objects, as you will need to hardcode such behaviour.

Depending on your exact needs, you could create some scripts for it as well.

The logic behind it is very simple.

You can give every VW object a unique name. This name can be used to get a handle to the object.

If you would create a script or an object, object A should remember the name of Object B so it can get the handle of it whenever required.

Share this post


Link to post

@Vincent C

I need a logic link. Just to get a handle for the other object. Grouping them means that, they 'stick' together which is not what I want.

@hippothamus

I already thought about using the name. But I don't want to do that, because of two issues:

- I'd need to program an auto-name routine within my script.

- I don't want to 'waste' the object name for my linking purposes.

My aim is the following:

I'd like to link symbol instances to polygons. The symbol instance would be part of a PIO and retrieves information from the linked polygon, for example the area or the perimeter.

I already made something very similar: it's a PIO with a symbol that merges with the polygon. It works, but the downside is, that moving the symbol within the PIO is clumsy.

So I'd like a symbol (or PIO with a symbol) that's geometrically independent from the linked polygon.

Share this post


Link to post

The name method will work if you only want to associate pairs of objects. You could also attach a record with an ID field to your associated objects.

To find associates, search for objects with records having the same ID. This would allow you to associate objects on different layers, which you cannot do with Groups. You can also associate multiple objects this way. You would not need AddAssociation, but you could still use it if you wanted.

Raymond

Share this post


Link to post

@MullinRJ

Thank you.

I thought about using an ID to link two objects together.

But the downside is, that I do not know how to build an algorithm to generate and maintain unique IDs within Vectorscript.

So I'd prefer a built-in routine to link to elements - if such a routine exists.

Share this post


Link to post
@MullinRJ

Thank you.

I thought about using an ID to link two objects together.

But the downside is, that I do not know how to build an algorithm to generate and maintain unique IDs within Vectorscript.

So I'd prefer a built-in routine to link to elements - if such a routine exists.

I think every object has it's own index, an ID. It's not the same as the unique name string that can be found in the info palette.

If you were to create a string, it's actually not so hard. Just a do while loop that creates a random string and checks to make sure such object does not exist, if it does it will continue looping for a new string..

I have some code lying around that handles connecting object by placing a reference into a record attached to it, but it's made with the SDK so you can't do anything with it in vs :)

Share this post


Link to post

There is a function to create IDs if this helps,

FUNCTION CreateUUID : STRING;

As far as I know, there is no magical function to link objects together other than by unique attributes such as ID, color, etc.

And using those known attributes to get a handle with

PROCEDURE ForEachObject(callback: PROCEDURE; c: CRITERIA);

The obvious way to do the linking would be to save the handle address but the way pio's work the address may change on every call.

Share this post


Link to post

@Miguel

Thank you very very much. That sounds good.

I'll try to attach a record with the ID to the rectangle and the same ID with as suffix to the symbol to bind them together. By selecting one of the two objects I hope I can get access to the other one using the ID.

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