Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get SCALE attribute then set it?

10 REPLIES 10
Reply
Message 1 of 11
Anonymous
1015 Views, 10 Replies

Get SCALE attribute then set it?

Im a newbie to autocad and lisp in general.  What I want to be able to do is read the scale from a drawing as shown:

 

2222.png

 

Its also shown as an attribute when I run the command ddatte:

 

tree.png

 

I want to be able to read this number from lisp because sometimes the scale shown is not what is set in the command dimscale.  So I want to take this value and set it in dimscale (maybe using a script).  I found code on how to get attribute values but am not sure how to use it or call it here:

 

http://www.lee-mac.com/attributefunctions.html#al

 

Can someone please help me form the code for how to:

 

1)Get the scale attribute value

 

2)Take that scale attribute value and run the command dimscale taking the value from 1.

 

Or even if you can show me how to do one of these steps.

10 REPLIES 10
Message 2 of 11
steve216586
in reply to: Anonymous

You can get that value by using a field. See attached.

"No one can make you feel inferior without your consent. "-Eleanor Roosevelt
Message 3 of 11
Anonymous
in reply to: steve216586

Hi Steve,

 

I guess I dont know how that is going to help me.  I need to grab this value dynamically and then set the dimscale based on this value.  I see the dialog you posted in your attached file but I dont know how to script out or lisp out this value?

Message 4 of 11
Anonymous
in reply to: steve216586

The issue I am having is I do see that it runs a command called _eattedit but it requires me to select a block...which then I can move the mouse and select a block.  But I want to automate this so that it selects the scale automatically without me haivng to select a block.  Isnt there a way to just get a scale value given a name or id ?

Message 5 of 11
steve216586
in reply to: Anonymous

Ok, let's start over. Are you plotting from Paperspace? I hope so, otherwise this method won't work, because you need a viewport.

 

You want to:

 

1)Get the scale attribute value

 

2)Take that scale attribute value and run the command dimscale taking the value from 1.

 

You want to:

 

I need to grab this value dynamically and then set the dimscale based on this value.

 

And:

 

But I want to automate this so that it selects the scale automatically without me haivng to select a block.

 

First, you need to find the value of the attribute. To do that, you need to identify the scale of the viewport through the means I sent with the picture. If that text is not an attribute, you will need to make it one.

 

Then, your lisp should identify the command _DIMSCALE and change it to the value of the attribute, which is the value of the viewport. It would be simpler to just grab the value of the viewport and change _DIMSCALE to that.

 

IMHO, it seems like you are wanting to automate an undefined from another undefined, I may just be misunderstanding but that is what it seems.

 

...because sometimes the scale shown is not what is set in the command dimscale

"No one can make you feel inferior without your consent. "-Eleanor Roosevelt
Message 6 of 11
Anonymous
in reply to: steve216586

steve,

 

Im kind of getting what you are saying but am still a bit confused.  Yes your screen shot helped me locate the attribute, as you see I have posted it in one of my replies...But I still don't understand how to pull this value?  Isnt there any lisp code I can use such that If I pass it an attribute name it gives me the value of that attribute?

 

Here is my issue, Our users use another application that when exported to autocad the scale of the text in the drawing does not match the scale listed in the title block (The attribute scale as you have mentioned).  So what happens is things look very strange...to fix it manually we have to rum DIMSCALE and set the scale to what the drawing scale attribute shows...and that is the value I need (SCALE ATTRIBUTE).  When we do it manually and refresh (drawing setup) then everything looks right.

 

As you can see this becomes tedious to do manually over and over and over.  So I want to place this in a lisp or script file to run it.

 

The steps are:

 

1) Get the attribute value (SCALE)

2) Take the value (from step 1 above) and use DIMSCALE to set the scale

 

Thats all I am trying to do.

Message 7 of 11
Anonymous
in reply to: steve216586

Steve if it helps here is a little more info.

 

Inside a lisp file I can do this:

 

(getvar "dimscale")

And this will print me the current dimscale, I can even take it a step further and do this:

 

(setvar "dimscale" 5)

 

This will set the dimscale for me...Awesome I am 90% there....

Now all I want to do is something like this:

 

setvar "dimscale" x)

 

Where x is the attribute value of Scale (The attribute field you had posted earlier), how can I get the value of that attribute and pass it to setvar?  Thats all I need.  I hope this makes sense?

 

Message 8 of 11
steve216586
in reply to: Anonymous

I understand now. Unfortunately, it sounds like the text "1:5" is not an attribute nor field after importing, just text. It needs to be a field or attribute. In my first reply the drawing scale was a field that drew its value from the viewport. The reverse, it seems, from what you are trying to accomplish.

 

Do you scale the drawing which is imported? If so you could use this string:

 

(setvar "dimscale" SCALFAC) ;Sets current
dimstyle scale factor porportional to the drawing scale factor.

 

As a last resort, maybe attach a drawing for me or others to take a look.

"No one can make you feel inferior without your consent. "-Eleanor Roosevelt
Message 9 of 11
Anonymous
in reply to: steve216586

When I try this:

 

 

(setvar "dimscale" SCALFAC)

 

Inside a lisp file and try to run the lisp inside the file I get this:

 

error: AutoCAD variable setting rejected: "dimscale" nil

Message 10 of 11
Anonymous
in reply to: steve216586

HI Steve,

 

You say its only text and needs to be an attribute?  Doesnt this confirm that it is an attribute / tag:

 

TESTTTTT.png

Message 11 of 11
steve216586
in reply to: Anonymous

Ok. So now you only need the lisp to call on the attribute. Code supplied courtesy of Lee Mac.

 

;; Get Attribute Value
;; Returns the value held by the specified tag within the supplied block, if present.
;; blk - [ent] Block (Insert) Entity Name
;; tag - [str] Attribute TagString
;; Returns: [str] Attribute value, else nil if tag is not found.

(defun LM:getattributevalue ( blk tag / enx )
    (if (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk)))))))
        (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
            (cdr (assoc 1 enx))
            (LM:getattributevalue blk tag)
        )
    )
)

 

Use block tag SCALE in your attribute list, as value of DIMSCALE.

"No one can make you feel inferior without your consent. "-Eleanor Roosevelt

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

Post to forums  

Autodesk Design & Make Report

”Boost