Jump to content

Convert dwgprops item to a float in field formula


MastroLube

Recommended Posts

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?

b6gsic5.png

I've tried with autolisp (atof ...) but it's not working.

Thanks! Dennis

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

  • 3 weeks later...

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

Link to comment
Share on other sites

  • 2 weeks later...

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

 

Link to comment
Share on other sites

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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...