Jump to content

Script to link text to record


Recommended Posts

Long back story here, but the quick summary is as follows.


We have a file here a guy is working on.  We have lots and lots of symbols in it.  I am trying to link one block of text in each symbol to one record field.  Right now we do the following. 


Select the symbol - Edit 2D - select the text - choose from the menu "link text to record" - choose the record & the field- exit the symbol.


What I am hoping is that I can generate some type of a script that after the text is selected would automatically go to "Menu - Tools - Records - Link Text to record - automatically choose the Format and the field in there as they are all the same and hit okay."


Is there any way to automate that into a script or something where we can just select 1 button to make everything execute as follow?

Link to comment

Yes and yes


There are mabye 6-12 blocks of text per symbol.  Most all the symbols already have this record applied to them, just not the text linked to record.


The hope is once the given text block is selected to save the couple of steps to link to that record and field.



Link to comment

I don't dare race you. :-)


I have some time tonight and travel time tomorrow.  I think I can figure it out.  As long as it doesn't need to be elegant.


Matt, if you need it before then, Pat could find 15 minutes and crank it out.





edit:  Pat, even if you do it, I probably give it a try, just for the fun/experience.

Edited by michaelk
Link to comment

No major hurry or anything just working on something here, it is an inventory of some pieces we own.  It can really be put together more or less whenever.  It is more of a curiosity thing.  I am also very curious how to do this myself.  I know some super basic scripting, but not sure how to execute this.  I would appreciate any insight.




Link to comment

Interesting.  @Pat Stanford I may turn this one over to you.  


What I thought was going to be simple is complicated by starting the script while inside the symbol definition.  Not sure how to proceed.  Is it necessary to create a dummy symbol and do a SetHDef(); ?  Or is it necessary to close the edit first?


I'm stumped.  I'm sure when I land you'll have an elegant 12 line script :-)




Link to comment

No.  The Get/SetObjectVariableInt(H1,1350/1351) do not seem to work at all. The only return I get from these calls is 0.


I am planning to submit a bug the next time I get a chance.  I tried Int, LongInt, String, Handle, Point, Boolean. None of them  return anything but zero for a text object in a symbol that is linked to a record or is not linked to a record.


Apologies for typos. Too much scotch.



Link to comment

Pat, like you, I've spent WAY more time on this than I intended, but I think I've got it — assuming I read the question correctly. Then I spent a bunch more time playing with it. All of it non billable, so I hope someone enjoys this besides me.


MattG, Having never worked with Linked Text before, I started out like a rank beginner. Now I understand how it works. It weren't [sic] obvious. I am also not sure I solved the problem you stated above. Hopefully I am close.


I'm attaching a v2013 file with 3 scripts. The first converts "symbols with selected text" to "symbols with Linked Text", and it makes a LOT of assumptions on how the file is set up. A list of the assumptions can be found at the top of the script. Use the Script Editor to read them. If anyone uses this script on their own files — WORK ON A COPY OF YOUR WORK – until you know the script does what you want. All Common Sense Disclaimers apply. 


Because this task starts with symbol instances and ends up modifying symbol definitions, it was necessary to make two passes to do it right. Here's my basic approach:
With each symbol instance:
    find the first selected text object inside the SymDef.
    attach the LinkedText record to the symbol instance.
    add the selected text from inside the SymDef to the record field.

Go back through each symbol instance:
    find the first selected text object inside the SymDef.
    attach the Linked Text record to the SymDef.

    add the selected text from inside the SymDef to the record field. This is the Default text when the symbol is placed.

    LinkText() from the selected text object to the Linked Text record and field.


The second script places symbols and modifies the Linked Text.

The third script resets the file to its initial state.


If anyone has any questions about what I've done, Pat will be happy to answer you.   ;-)



Link SymText to Sym v2013.vwx

  • Like 1
Link to comment
  • 1 year later...

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.

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