MastroLube Posted November 6, 2018 Share Posted November 6, 2018 Hello everyone! Is it possible to link a field to a lisp variable? I want to store that variable via lisp and I was wondering if it's possible to have that value inside some fields in the drawing. I don't find my custom names of variable inside that list. Thank you for your help! Dennis Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted November 6, 2018 Share Posted November 6, 2018 It works fine here for me. I can see all of my global lisp variables that get set with "acaddoc.lsp" and I can simply set a new one [example: (setq aaaa 1.5)] and it shows up in the list. Note that lisp variables are document specific. If you set a variable in document 1, it will not exist in document 2 (at least not without some action on your end). Quote Link to comment Share on other sites More sharing options...
MastroLube Posted November 6, 2018 Author Share Posted November 6, 2018 1 hour ago, rkmcswain said: It works fine here for me. I can see all of my global lisp variables that get set with "acaddoc.lsp" and I can simply set a new one [example: (setq aaaa 1.5)] and it shows up in the list. Note that lisp variables are document specific. If you set a variable in document 1, it will not exist in document 2 (at least not without some action on your end). Hello! Thanks, I've tried and it worked.. Is it possible to have that variable stored in the dwg and link to it? Thank for your help Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted November 6, 2018 Share Posted November 6, 2018 Do you mean you want to store a persistent variable in the drawing file, without using lisp code to set the variable each time the drawing opens? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 6, 2018 Share Posted November 6, 2018 7 hours ago, MastroLube said: Is it possible to have that variable stored in the dwg and link to it? Whilst you can quite easily store the data bound to a variable in the drawing in a number of different ways (e.g. drawing dictionary / xdata / ldata), you would then need to develop a program to run on drawing startup from the acaddoc.lsp file to read the stored data and define the variables you intend to reference in your fields. You could alternatively make use of the set of USER*1-5 system variables which are stored per drawing and may hold integer, real or string values, and then reference such values directly from a field. Quote Link to comment Share on other sites More sharing options...
Grrr Posted November 6, 2018 Share Posted November 6, 2018 5 minutes ago, Lee Mac said: you would then need to develop a program to run on drawing startup from the acaddoc.lsp Lee, sorry for the aside question - If one defines persistent reactor, would other be able to run/use it from the drawing without loading any .lsp routine(s) I was wondering did you ever found an answer from this thread Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 6, 2018 Share Posted November 6, 2018 (edited) 1 hour ago, Grrr said: If one defines persistent reactor, would other be able to run/use it from the drawing without loading any .lsp routine(s) In short, no - not using standard functionality. There was a discussion some time ago at the Swamp regarding the discovery of a glitch by Luis (aka 'LE' / 'Spike Wilbury') in which a separate-namespace VLX could be embedded into a drawing and therefore evaluated by means of a persistent reactor - some could reproduce the glitch, others could not. Obviously the topic was extremely controversial given that the prospect of this possibility presents a huge security risk and is not something I would suggest pursuing. Edited November 6, 2018 by Lee Mac 1 Quote Link to comment Share on other sites More sharing options...
MastroLube Posted November 7, 2018 Author Share Posted November 7, 2018 (edited) Hello guys! Thanks for your help! I've 7 strings that I want to insert inside 7 fields that are inside a block. Currently there is only 1 field. In order to modify these values I can search for the entity handle (for example (5 . "178AB78")). It should stay always the same, right? (I know that entity name change every time I open the dwg) I've tried with that (ssget "_X" (list (cons 5 "178AB78"))) but I got a NIL. The problem maybe is that that it is inside a block on paper space. Maybe I can attach some XDATA to link to them.. What's your opinion? Is it possible if it's inside a block on paper space? A side question is: I've set the var "users1" for a string but I don't know hot to link to that inside a field.. Where is the option? I can do everything from here using a combination of USERR-1 5 and USERS-1 5, but I need to know how to link to these variables using the field Thanks! Dennis EDIT: ok it looks like that USERS are not persistent .. Edited November 7, 2018 by MastroLube Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted November 7, 2018 Share Posted November 7, 2018 You could try to retrieve ENAME, by using (handent) function : (handent "178AB78") - no need for (ssget) - each handle is unique to exactly 1 ename... Yes you're right USERS aren't persistent, and I think they have limitation of quantity of data they can hold... You could try to save data to variables, and then export variables to *.txt file, after which when you open new DWG you could load them and import in memory (atoms-family) as globals... You could try to automate importing, but exporting must be done manually - of course through lisp... See this : http://www.theswamp.org/index.php?topic=50628.msg557923#msg557923 HTH., M.R. 1 Quote Link to comment Share on other sites More sharing options...
MastroLube Posted November 7, 2018 Author Share Posted November 7, 2018 Hello marko! Thank you for that function "handent" !!! I wrote that but the block didn't update! If I enter the editor it's fine. Is it possible to update it without entering the editor and using the reset block? I have some attribute that I don't want to miss... Thanks! Quote Link to comment Share on other sites More sharing options...
tombu Posted November 7, 2018 Share Posted November 7, 2018 Custom properties are saved in each drawing and can be found in the Field dialog box category under Document which seems to be the functionality you're looking for. I use lisp to create and modify custom properties that are referenced as fields in title blocks like who it was drawn by and who's going to sign it. I have one lisp that adds our common custom properties, another for selecting from a list of engineers in our office in a dialog box who's going to sign it, and another that simply sets the current user as who it was drawn by. Quote Link to comment Share on other sites More sharing options...
MastroLube Posted November 7, 2018 Author Share Posted November 7, 2018 Hello! I don't find that USERI1 inside that category and in anything else.. But maybe I'm blind Are you sure about Document as Field Category? Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted November 7, 2018 Share Posted November 7, 2018 You're right @MastroLube - I don't see the userX sysvars in the FIELD UI. But you can create the appropriate field like this: (setq ostr "%<\\AcVar useri1>%") (command "mtext" (getpoint) "w" "0" ostr "") 1 Quote Link to comment Share on other sites More sharing options...
tombu Posted November 7, 2018 Share Posted November 7, 2018 29 minutes ago, MastroLube said: Are you sure about Document as Field Category? Enter DWGPROPS at the command line, pick the Custom tab, pick [Add…] and enter a name and value for the custom property, then click [OK] and check the Document Field Category again. 1 Quote Link to comment Share on other sites More sharing options...
MastroLube Posted November 7, 2018 Author Share Posted November 7, 2018 (edited) 1 hour ago, tombu said: WOW!!! What kind of sorcery is that?? ahaha How can I set these "custom proprieties" by lisp? Thanks I found that (defun C:Test (/ App Doc DwgProps) (setq App (vlax-Get-Acad-Object) Doc (vla-Get-ActiveDocument App) DwgProps (vla-Get-SummaryInfo Doc)) (vla-AddCustomInfo DwgProps "n_gabbiess" "No Data") (vla-AddCustomInfo DwgProps "Sample2" "No Data") (vla-SetCustomByIndex DwgProps 0 "Sample1" "Some data") (vla-SetCustomByKey DwgProps "n_gabbie" "1234") (princ)) A little question: I want to insert a cycle to see if there are these values and if not create them.. I'm not able to get their value but only to set. I don't find the right syntax (IF (vla-GetCustomByKey summaryInfo "n_gabbie" 'value) (progn (vla-AddCustomInfo summaryInfo "n_alleggerimenti" "xxxx") (vla-AddCustomInfo summaryInfo "n_gabbie" "xxxx") (vla-AddCustomInfo summaryInfo "incidenza_cls" "xxxx") ) ) Looks like that in SummaryInfo there are any custom key :S But if I try to create them with the same name I get the error "already exist" (setq App (vlax-Get-Acad-Object) Doc (vla-Get-ActiveDocument App) summaryInfo (vla-Get-SummaryInfo Doc) ) Edited November 7, 2018 by MastroLube 1 Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted November 7, 2018 Share Posted November 7, 2018 FYI: USERI1 etc. should be listed under SystemVariable. Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted November 7, 2018 Share Posted November 7, 2018 3 minutes ago, Roy_043 said: FYI: USERI1 etc. should be listed under SystemVariable. But it's not. Hence this post. Quote Link to comment Share on other sites More sharing options...
MastroLube Posted November 7, 2018 Author Share Posted November 7, 2018 Ok, now I get how this function works thanks to this code: (defun GetCustomInfo ( / Info Num Index Custom) (and (vl-load-com) (or *acad* (setq *acad* (vlax-get-acad-object))) (or *doc* (setq *doc* (vlax-get *acad* 'ActiveDocument))) (vlax-property-available-p *doc* 'SummaryInfo) (setq Info (vlax-get *doc* 'SummaryInfo)) (setq Num (vla-NumCustomInfo Info)) (setq Index 0) (repeat Num (vla-getCustomByIndex Info Index 'ID 'Value) (setq Custom (cons (cons ID Value) Custom)) (setq Index (1+ Index)) );repeat );and (if Custom (reverse Custom)) ); defun And this is mine: (vla-GetCustomByKey summaryInfo "n_alleggerimenti" 'Value) (IF (not Value) (progn (vla-AddCustomInfo summaryInfo "n_alleggerimenti" "xxxx") (vla-AddCustomInfo summaryInfo "n_gabbie" "xxxx") (vla-AddCustomInfo summaryInfo "incidenza_cls" "xxxx") ) ) Thank you all guys! <3<3<3<3<3<3 1 Quote Link to comment Share on other sites More sharing options...
tombu Posted November 7, 2018 Share Posted November 7, 2018 You can use USERI1 in Field category Other as a DieselExpression, pasted in as $(getvar, USERI1) I'd still go with Custom Properties though. 1 Quote Link to comment Share on other sites More sharing options...
Grrr Posted November 8, 2018 Share Posted November 8, 2018 Okay, I did a small investigation on this: (setq SumInfo (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object)))) (vla-AddCustomInfo SumInfo "MySummaryKey" "MyValue123") /* ; then type the "FIELD" command, and you'll find "MySummaryKey" under the field names ; place the field somewhere as mtext, and it will contain "MyValue123" ; to redefine the FIELD contents, use: */ (vla-RemoveCustomByKey SumInfo "MySummaryKey") (vla-AddCustomInfo SumInfo "MySummaryKey" "MyNewValue123") /* ; and then use REGEN command, so the MTEXT's FIELD content will change to "MyNewValue123" ; note that MySummaryKey is null (not found as an assigned symbol within lisp) */ // ...No LISP style for the colored comments, so I used C Looks like it uses associative type of data for storing and retrieving (<key> <value>), although by "Lisp Variable" I understand assigning some lisp type of value to a symbol, that one would be able to retrieve. And the above has nothing to do with my assumption. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.