MastroLube Posted February 2, 2023 Posted February 2, 2023 Hi there! I have a lisp that saves a custom variable in my dwg. (the custom tab in dwgprops command) I want to insert that value in a field and manipulate it a little bit, but it's a string. Is it possible to convert it to a float inside the formula box in the field editor? I've tried with autolisp (atof ...) but it's not working. Thanks! Dennis Quote
BIGAL Posted February 2, 2023 Posted February 2, 2023 Show your code that is possibly where problem is. Quote
MastroLube Posted February 3, 2023 Author Posted February 3, 2023 Hello BIGAL, thanks for reply! This is the exatracted code: (defun AX:getCustomDwgProp (key / app doc dwgprops try val) (vl-load-com) (setq App (vlax-Get-Acad-Object) Doc (vla-Get-ActiveDocument App) DwgProps (vla-Get-SummaryInfo Doc) ) (cond ((vl-catch-all-error-p (setq try (vl-catch-all-apply 'vla-GetCustomByKey (list DwgProps key 'val) ) ) ) (setq val nil) ) ) val ) (defun AX:SetCustomDwgProp (key value / App Doc DwgProps) (vl-load-com) (setq App (vlax-Get-Acad-Object) Doc (vla-Get-ActiveDocument App) DwgProps (vla-Get-SummaryInfo Doc) ) (if (AX:getCustomDwgProp key) (vla-SetCustomByKey DwgProps key value) (vla-AddCustomInfo DwgProps key value) ) ) ; example: (AX:SetCustomDwgProp "_H_Legatura" (+ (nth 1 solaio) (nth 3 solaio) (nth 5 solaio) 0.5 2) ) The sum returns a float for sure, but I think that in custom prop you can only have string objects (so it's automatically converted). You can also try to create a custom key manually as showed in the video attached. As you can see, I have only strings methods on it (uppercase, lowercase and so on). Maybe there is a better way to store a value that can be reached from a field? I don't think dictionaries is the correct way, because you need a lisp that update these values and you can't copy text using standard copy function. I wanted to keep it is simple but maybe it's not possible.. Any idea? Thanks! 2023-02-03-11-25-54.mp4 Quote
BIGAL Posted February 4, 2023 Posted February 4, 2023 LDATA ? (vlax-ldata-put "AlanH" "Ahscale" 100) (setq ahsc (vlax-ldata-get "AlanH" "Ahscale")) Multiple keys in "AlanH" Quote
MastroLube Posted February 23, 2023 Author Posted February 23, 2023 unfortunately, LDATA can't be accessed using fields (sorry for late answer) Perhaps at this point it makes more sense to handle the text as an object and update it each time the code is run, since dwgprops cannot be used to do mathematical operations (having no way inside the field to convert them) Another way could be to save multiple dwgprops with the various results, and access those Quote
ketxu Posted March 4, 2023 Posted March 4, 2023 Please store customprops format 25.5 instead of 25,5 So, you can change float value from sum to string (by rtos ...) before pass to AX:SetCustomDwgProp function, or modify function like that (defun AX:SetCustomDwgProp (key value / App Doc DwgProps) (vl-load-com) (setq App (vlax-Get-Acad-Object) Doc (vla-Get-ActiveDocument App) DwgProps (vla-Get-SummaryInfo Doc) ) (if (AX:getCustomDwgProp key) (vla-SetCustomByKey DwgProps key value) (vla-AddCustomInfo DwgProps key value) ) ;Add more to , -> . sure (vla-SetCustomByKey DwgProps key (vl-string-translate "," "." (AX:getCustomDwgProp key))) ) Quote
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.