Jump to content

how to grab values from different objects?


gilsoto13

Recommended Posts

Hi, Guys..

 

This is not an important task, but it will help me a little bit everyday...

 

I will like to find a routine to allow me to pick one object, either a text, mtext, block, leader or dimension, either in model or paper space, and automatically update the dimscale factor taking the value from the picked object.

 

- from text or mtext height, Dimscale = (Text height) * 8

- from Block x value factor, Dimscale = (block x value factor) positive value in case being negative

- from Dimension or leader, Dimscale = Dimscale factor

 

This is to be used to update other objects with a lispt, taking the Dimscale from another object.

Link to comment
Share on other sites

That means "Dimscale factor" for Dimension or leader, I have assumed, that it is a LinearScaleFactor, but it is only at Dimension?

(defun get_dimscal ( obj / type_obj)
 (vl-load-com)
 (if (setq type_obj (cdr(assoc 0 (entget obj ))))
   (cond
     ((wcmatch type_obj "*TEXT")(* (cdr(assoc 40 (entget obj))) )
     ((eq type_obj "INSERT")(abs (cdr (assoc 41 (entget obj)))))
     ((eq type_obj "DIMENSION")(vla-get-LinearScaleFactor(vlax-ename->vla-Object obj)))
     (T T)
     )))

 

The function test, has been selected Мtext with height 5

Command: (get_dimscal(car(entsel)))

Select object: 40.0

Link to comment
Share on other sites

That means "Dimscale factor" for Dimension or leader, I have assumed, that it is a LinearScaleFactor, but it is only at Dimension?

 

mmmm... I don´t know... I would test it adding the leader type... and check what happen..

 

But it seems the right code... but I cannot test it... since I am not a programmer, I just don´t know where the problem might be..

 

I didn´t check it as a subfunction, just added c:

but I got this

 

Command: get_dimscal

; error: too few arguments

 

Any ideas?

Link to comment
Share on other sites

The function is a sub-function, requiring an entity (ename) argument.

 

well, I understood that... but no matter how many times I try to make a lisp to complete it... my coding knowledgment is pretty basic .... I guess the next step for me will be to read and understand the manuals or just try to find a similar lisp to understand it... but well...

 

It is a good start so far.

 

And I think It's almost done

 

;;
(defun get_dimscal ( obj / type_obj)
 (vl-load-com)
 (if (setq type_obj (cdr(assoc 0 (entget obj ))))
   (cond
     ((wcmatch type_obj "*TEXT")(* (cdr(assoc 40 (entget obj))) )
     ((eq type_obj "INSERT")(abs (cdr (assoc 41 (entget obj)))))
     ((eq type_obj "DIMENSION")(vla-get-LinearScaleFactor(vlax-ename->vla-Object obj)))
     (T T)
     )))

(defun c:ddddd () 
(princ (get_dimscal (car (entsel))))
)

 

I am getting the value, but how to change the dimscale variable with it?

 

oooOOOH...

 

I got it..

 

;; It automatically changes the dimscale factor taking it from a
;; selected object
;; Geobuilder -- 2010
;; [url]http://www.cadtutor.net/forum/showthread.php?p=304557#post304557[/url]
;; SUB-FUNCTION
(defun get_dimscal ( obj / type_obj)
 (vl-load-com)
 (if (setq type_obj (cdr(assoc 0 (entget obj ))))
   (cond
     ((wcmatch type_obj "*TEXT")(* (cdr(assoc 40 (entget obj))) )
     ((eq type_obj "INSERT")(abs (cdr (assoc 41 (entget obj)))))
     ((eq type_obj "DIMENSION")(vla-get-LinearScaleFactor(vlax-ename->vla-Object obj)))
     (T T)
     )))
(defun c:dre () 
(setvar "dimscale" (get_dimscal (car (entsel))))
)

 

tank you guys.... works great

Link to comment
Share on other sites

Gilsoto,

 

Not sure what you are really trying to do, or what you are looking for when it comes to Dimensions/Leaders, but if I have understood correctly:

 

(defun c:MrGilsoto (/ dxf ent)

 (defun dxf (code ent) (cdr (assoc code (entget ent))))

 (cond (  (setq ent (car (entsel)))

          (setvar 'DIMSCALE

            (cond (  (wcmatch (dxf 0 ent) "TEXT,MTEXT") (* 8. (dxf 40 ent)))

                  (  (eq "INSERT" (dxf 0 ent)) (dxf 41 ent))
                        
                  (  (getvar "DIMSCALE"))))))
 (princ))

Link to comment
Share on other sites

OOOK...

 

Yeah, I had a problem with dimensions and leaders...

ouk... I just went to post this thread without much investigation...

About dimensions and leader I need to run a command instead of getting the LinearScaleFactor, for those objects I need to run the

command "dimstyle""restore". So the dimscale value gets updated.

 

I'll check out if I can do do it myself.

 

Gilsoto,

 

Not sure what you are really trying to do, or what you are looking for when it comes to Dimensions/Leaders, but if I have understood correctly:

 

(defun c:MrGilsoto (/ dxf ent)

 (defun dxf (code ent) (cdr (assoc code (entget ent))))

 (cond (  (setq ent (car (entsel)))

          (setvar 'DIMSCALE

            (cond (  (wcmatch (dxf 0 ent) "TEXT,MTEXT") (* 8. (dxf 40 ent)))

                  (  (eq "INSERT" (dxf 0 ent)) (dxf 41 ent))

                  (  (getvar "DIMSCALE"))))))
 (princ))

 

 

nooup... I tried the command and vl-cmdf in Geobuilder's lisp, but I get the malformed list on input error.

 

and I added a row for dimensions in your Lisp, Lee, but I don´t know the dxf code for dimscale factor from a dimension style... I am a little stuck again, but Blocks, text and mtext work perfect in both lisp routines.

Link to comment
Share on other sites

This sets the DIMSCALE as per the dimstyle of the selected object, but doesn't use restore:

 

(defun c:MrGilsoto (/ dxf ent)

 (defun dxf (code ent) (cdr (assoc code (entget ent))))

 (cond (  (setq ent (car (entsel)))

          (setvar 'DIMSCALE

            (cond (  (wcmatch (dxf 0 ent) "TEXT,MTEXT") (* 8. (dxf 40 ent)))

                  (  (eq "INSERT" (dxf 0 ent)) (dxf 41 ent))

                  (  (wcmatch (dxf 0 ent) "DIMENSION,*LEADER")

                     (cdr (assoc 40 (tblsearch "DIMSTYLE" (dxf 3 ent)))))

                  (  (getvar "DIMSCALE"))))))
 (princ))

 

PS> What on earth does: 'ouk' and 'nooup',.. mean? :unsure:

Link to comment
Share on other sites

jjajaja, Add this one too:

yep..

 

They mean

oouk... ouk... mean ok

noup... neeeup.. mean no

yep... mean yes

 

This sets the DIMSCALE as per the dimstyle of the selected object, but doesn't use restore:

 

(defun c:MrGilsoto (/ dxf ent)

 (defun dxf (code ent) (cdr (assoc code (entget ent))))

 (cond (  (setq ent (car (entsel)))

          (setvar 'DIMSCALE

            (cond (  (wcmatch (dxf 0 ent) "TEXT,MTEXT") (* 8. (dxf 40 ent)))

                  (  (eq "INSERT" (dxf 0 ent)) (dxf 41 ent))

                  (  (wcmatch (dxf 0 ent) "DIMENSION,*LEADER")

                     (cdr (assoc 40 (tblsearch "DIMSTYLE" (dxf 3 ent)))))

                  (  (getvar "DIMSCALE"))))))
 (princ))

 

PS> What on earth does: 'ouk' and 'nooup',.. mean? :unsure:

 

 

 

and yep... This is what I meant... Now I got a brand new utility to update my things...

 

thanks Lee.... Now I can rest a little and ckeck the other one...

Link to comment
Share on other sites

and yep... This is what I meant... Now I got a brand new utility to update my things...

 

thanks Lee.... Now I can rest a little and ckeck the other one...

 

You're welcome,

 

Its not such a difficult LISP to understand, just use this to decipher the DXF group codes that I use:

 

http://autodesk.com/techpubs/autocad/acad2000/dxf/

Link to comment
Share on other sites

Great... anyway I wouldn´t have been able to solve it myself.. combining DXF with tablesearch and wcmatch... it's too far away from my possibilities... I would have taken a whole day to catch it... after testing the lisp 300 hundred times...

:s

Link to comment
Share on other sites

Great... anyway I wouldn´t have been able to solve it myself.. combining DXF with tablesearch and wcmatch... it's too far away from my possibilities... I would have taken a whole day to catch it... after testing the lisp 300 hundred times...

:s

 

Its all just DXF knowledge really, there are many ways to do it - I just like to be concise. :wink:

Link to comment
Share on other sites

Yes, all is good.

But I never used this variable, certainly I have found its appointment in help, but to try and it has not turned out, my AutoCAD rejects its any new value, though in manual, though through Lee Maс's Lisp. And with Mleader does not work:(

Link to comment
Share on other sites

Two more things... I tried several ways to add a simple message at the end with

 

strcat Dimscale has been set to: (dmscl)

 

And also your lisp gets stuck with Blocks with negative x values... how could you get the positive x value to be able to update dimscale?

 

I had a code for it... but its does not work with dxf values.

Link to comment
Share on other sites

(defun c:MrGilsoto (/ dxf ent)

 (defun dxf (code ent) (cdr (assoc code (entget ent))))

 (cond (  (setq ent (car (entsel)))

          (setvar 'DIMSCALE

            (cond (  (wcmatch (dxf 0 ent) "TEXT,MTEXT") (* 8. (dxf 40 ent)))

                  (  (eq "INSERT" (dxf 0 ent)) [color=Red][b](abs[/b][/color] (dxf 41 ent)[b][color=Red])[/color][/b])

                  (  (wcmatch (dxf 0 ent) "DIMENSION,*LEADER")

                     (cdr (assoc 40 (tblsearch "DIMSTYLE" (dxf 3 ent)))))

                  (  (getvar "DIMSCALE"))))))

 [color=Navy][b](princ (strcat "\n<<--  Mr Gilsoto's Dimscale is: " (rtos (getvar 'DIMSCALE)) " -->>"))[/b][/color]
 (princ))

Link to comment
Share on other sites

  • 1 month later...

ok.... there was something bothering me in this lisp... I wanted dimscale factor to be updated according to those 3 different objects... but also preferred to grab all the Dimension variables (including dimscale) from a specific dimension style of a picked dimension or a leader... so I made some tests.. and I almost acomplished what I wanted... by changing one line...

 

 
;; Updates Dimscale variable taking the value from a Text or Mtext Object multiplied by 8
;; from a Block X positive value, and from any dimension or leader Dimscale
;; Lee MacDonnell February 2010
;; [url]http://www.cadtutor.net/forum/showthread.php?t=44989[/url]
(defun c:dre8 (/ dxf ent)

 (defun dxf (code ent) (cdr (assoc code (entget ent))))

 (cond (  (setq ent (car (entsel)))

          (setvar 'DIMSCALE

            (cond (  (wcmatch (dxf 0 ent) "TEXT,MTEXT") (* 8. (dxf 40 ent)))

                  (  (eq "INSERT" (dxf 0 ent)) (abs (dxf 41 ent)))
                  (  (wcmatch (dxf 0 ent) "DIMENSION,*LEADER")
           [color=red]          (command "dim""restore""" ent "exit"))[/color]
                  (  (getvar "DIMSCALE"))))))
 (princ (strcat "\n<<-- Dimscale has been set to: " (rtos (getvar 'DIMSCALE)) " -->>"))
 (princ))

 

The only problem is that I get an error message when I pick dimensions or leaders... but I get the style and dimscale updated correctly... is just the error message due the lisp format I don´t really understand... but If you (Lee) can correct it... would be nice... anyway it works right now.

 

Command: dre

Select object: AutoCAD variable setting rejected: DIMSCALE nil

Link to comment
Share on other sites

Incrediblll....

 

I made it myself ... just by testing... I tried the "(if" and checked for the parenthesis... and worked... i think I am becoming a programmer.... careful!!

 

 
;; Updates Dimscale variable taking the value from a Text or Mtext Object multiplied by 8
;; from a Block X positive value, and from any dimension or leader Dimscale
;; Lee MacDonnell February 2010
;; [url]http://www.cadtutor.net/forum/showthread.php?t=44989[/url]
(defun c:dre (/ dxf ent)

 (defun dxf (code ent) (cdr (assoc code (entget ent))))

 (cond (  (setq ent (car (entsel)))

          (setvar 'DIMSCALE

            (cond (  (wcmatch (dxf 0 ent) "TEXT,MTEXT") (* 8. (dxf 40 ent)))

                  (  (eq "INSERT" (dxf 0 ent)) (abs (dxf 41 ent)))
                  (  (getvar "DIMSCALE"))))))
                 
   (if (wcmatch (dxf 0 ent) "DIMENSION,*LEADER")
                     (command "dim""restore""" ent "exit"))
 (princ (strcat "\n<<-- Dimscale has been set to: " (rtos (getvar 'DIMSCALE)) " -->>"))
 (princ))

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