Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Applying variable to Attribute.

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
CSM_MAI
195 Views, 5 Replies

Applying variable to Attribute.

I'm having a problem with a callback error on a lisp i'm trying to piece together. I would like to get the dimscale of a drawing and then apply it to an attribute when a client border is inserted. I have a lisp that will change the attribute to what I want, and I have the code to get the DIMSCALE, but I can't seem to get them to work together.

 

Initially, when I type (getvar "dimscale") it will return the dimscale. i.e. 1.0, 24.0, 48.0   I would like for it to only show the number and not the ".0" portion of it. This may not be possible, I am not certain.  This code is probably garbage, but if anyone has any tips on getting this achieved it would be appreciated.  I had initially thought to setq a as the dimscale, and then try to aply that to the -attedit command, but had no luck. It now just says DIMSCALE where I want the number to go.

 

(defun C:iddim ( / a )
(vl-load-com)
(setq a (substr (getvar "dimscale")1 2))    
(command "-attedit" "y" "*" "TITLESCALE" "" "-999999,-999999" "999999,999999" "" "v" "r" "DIMSCALE" "")
(princ)
)

5 REPLIES 5
Message 2 of 6
Jason.Piercey
in reply to: CSM_MAI


@CSM_MAI wrote:

 

Initially, when I type (getvar "dimscale") it will return the dimscale. i.e. 1.0, 24.0, 48.0   I would like for it to only show the number and not the ".0" portion of it. This may not be possible, I am not certain.


One way to drop the decimal point

 

(rtos (getvar "dimscale") 4 0)

Message 3 of 6
Lee_Mac
in reply to: CSM_MAI

How about using a field? For example:

 

(defun c:iddim ( / i s )
    (if (setq s (ssget "_X" '((0 . "INSERT") (66 . 1))))
        (repeat (setq i (sslength s))
            (foreach a (vlax-invoke (vlax-ename->vla-object (ssname s (setq i (1- i)))) 'getattributes)
                (if (= "TITLESCALE" (strcase (vla-get-tagstring a)))
                    (vla-put-textstring a "%<\\AcVar dimscale \\f \"%lu2%pr0\">%")
                )
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

You may need to regen the drawing to update the field.

Message 4 of 6
CSM_MAI
in reply to: Lee_Mac

I had thought about using fields, but the client is pretty adamant about not adding items such as fields to their borders. They have programs that end up extracting the data from the title block once submitted to them and potential conflicts could arise from that, (so they say).

Message 5 of 6
Lee_Mac
in reply to: CSM_MAI

OK, in that case, in my code change:

 

(vla-put-textstring a "%<\\AcVar dimscale \\f \"%lu2%pr0\">%")

 

To:

 

(vla-put-textstring a (rtos (getvar 'dimscale) 2 0))

 

Message 6 of 6
CSM_MAI
in reply to: CSM_MAI

Thanks, for the ratios helped out. I changed the 4 to a 2 for decimal units, and it change the attribute when the command was activated.

 

(defun C:iddim ( / a )
(vl-load-com)
(setq a (rtos (getvar "dimscale") 2 0))
(command "-attedit" "y" "*" "TITLESCALE" "" "-999999,-999999" "999999,999999" "" "v" "r" a "")
(princ)
)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

”Boost