Let say that i have a text object that has more then one annotative scale. When i do a list command one it, i can see the current annotative scale. How can i retreive that scale with lisp or vlisp ?
|
Let say that i have a text object that has more then one annotative scale. When i do a list command one it, i can see the current annotative scale. How can i retreive that scale with lisp or vlisp ?
You can try using the CANNOSCALE and CANNOSCALEVALUE variables.
What I think the OP means is he wanted to find the scales attached to the annotative entity, not the currently set scale. The list command shows what scale the entity is displaying at present - even if CANNOSCALE is set to something different it still shows the default scale for that entity.
I've also been looking for this and come through an inspection exercise. It's not so easy - the scales are listed 4 levels deep into sub-entities. E.g. going through an annotative dimension (with 2 scales attached) with the following typed at the command line and picking the dim:Now I know the 330 will point me to the *ModelSpace block, the only other sub-entity is under 360 as an XDictionary. Thus I did the following:Code:Command: (setq ed (entget (car en))) ((-1 . <Entity name: 7670d988>) (0 . "DIMENSION") (5 . "5D9") (102 . "{ACAD_XDICTIONARY") (360 . <Entity name: 7670d990>) (102 . "}") (330 . <Entity name: 78942c10>) (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbDimension") (2 . "*D19") (10 2846.52 2165.39 0.0) (11 2301.51 2345.39 0.0) (12 0.0 0.0 0.0) (70 . 32) (1 . "") (71 . 5) (72 . 1) (41 . 1.0) (42 . 1090.02) (73 . 0) (74 . 0) (75 . 0) (52 . 0.0) (53 . 0.0) (54 . 0.0) (51 . 0.0) (210 0.0 0.0 1.0) (3 . "DIM-A") (100 . "AcDbAlignedDimension") (13 1756.5 1177.15 0.0) (14 2846.52 1177.15 0.0) (15 0.0 0.0 0.0) (16 0.0 0.0 0.0) (40 . 0.0) (50 . 0.0) (100 . "AcDbRotatedDimension"))This don't show too much nice thing does it? Whell there's another 360 code ... so:Code:(setq en1 (cdr (assoc 360 ed)) ed1 (entget en1)) ((-1 . <Entity name: 7670d990>) (0 . "DICTIONARY") (330 . <Entity name: 7670d988>) (5 . "5DA") (100 . "AcDbDictionary") (280 . 1) (281 . 1) (3 . "AcDbContextDataManager") (360 . <Entity name: 7670d998>))At least now I know I'm on the right track (3 . "ACDB_ANNOTATIONSCALES") sounds like its got something to do with AnnoScales. Here's a 350 code ... so yet again:Code:(setq en2 (cdr (assoc 360 ed1)) ed2 (entget en2)) ((-1 . <Entity name: 7670d998>) (0 . "DICTIONARY") (5 . "5DB") (102 . "{ACAD_REACTORS") (330 . <Entity name: 7670d990>) (102 . "}") (330 . <Entity name: 7670d990>) (100 . "AcDbDictionary") (280 . 0) (281 . 1) (3 . "ACDB_ANNOTATIONSCALES") (350 . <Entity name: 7670d9a0>))Now there's 2 off 350 codes - briliant! This seems it's going to give me what I want. So ...Code:(setq en3 (cdr (assoc 350 ed2)) ed3 (entget en3)) ((-1 . <Entity name: 7670d9a0>) (0 . "DICTIONARY") (5 . "5DC") (102 . "{ACAD_REACTORS") (330 . <Entity name: 7670d998>) (102 . "}") (330 . <Entity name: 7670d998>) (100 . "AcDbDictionary") (280 . 0) (281 . 1) (3 . "*A2") (350 . <Entity name: 7670dab8>) (3 . "*A3") (350 . <Entity name: 7670dba0>))Aaaaaggggghhh! WTF? ... OK try again ... there's a 340 code nowCode:(setq en4 (cdr (assoc 350 ed3)) ed4 (entget en4)) ((-1 . <Entity name: 7670dab8>) (0 . "ACDB_ALDIMOBJECTCONTEXTDATA_CLASS") (5 . "5FF") (102 . "{ACAD_REACTORS") (330 . <Entity name: 7670d9a0>) (102 . "}") (330 . <Entity name: 7670d9a0>) (100 . "AcDbObjectContextData") (70 . 3) (290 . 1) (100 . "AcDbAnnotScaleObjectContextData") (340 . <Entity name: 7670d358>) (100 . "AcDbDimensionObjectContextData") (2 . "*D19") (293 . 0) (10 2301.51 2345.39 0.0) (294 . 1) (140 . 0.0) (298 . 0) (291 . 0) (70 . 0) (292 . 0) (71 . 0) (280 . 0) (295 . 0) (296 . 0) (297 . 0) (100 . "AcDbAlignedDimensionObjectContextData") (11 2846.52 2165.39 0.0))Yippeeeee! That's the 1st scale set to the dim. The 300 code shows the scale's name (300 . "1:100") while the 140 and 141 shows the factors.Code:(setq en5 (cdr (assoc 340 ed4)) ed5 (entget en5)) ((-1 . <Entity name: 7670d358>) (0 . "SCALE") (5 . "4A3") (102 . "{ACAD_REACTORS") (330 . <Entity name: 789712d8>) (102 . "}") (330 . <Entity name: 789712d8>) (100 . "AcDbScale") (70 . 0) (300 . "1:100") (140 . 1.0) (141 . 100.0) (290 . 0))
So to recap:
Repeat steps 3, 4 & 5 for the next links. E.g. use the (setq en3 (cdr (assoc 350 (cdr (member (assoc 350 ed2))))) ed3 (entget en3)) for the 2nd scale. Then repeat 4 & 5.
- From the entity's data obtain the dictionary item from the 360 code.
- Then from that data get the next dictionary with a 360 assoc again.
- Then from the AnnoScales dictionary, get the assoc of 350.
- Now get the 1st 350 to get the 1st scale link
- Then get it's 340 pointer to the actual scale entity.
Last edited by irneb; 2008-07-18 at 10:50 AM.
In which case it's a combination of the two. You first obtain a list of scales attached to the entity. Then check if CANNOSCALE is the same as one of those in the list - if it is then that's the one displayed. Otherwise (if CANNOSCALE is different to any of those in the list) then the 1st in the list is displayed.
In my example I've got the dim set to 1:100 and 1:200 (in that order). If CANNOSCALE = 1:50 the 1:100 version is displayed. If set to 1:250 the 1:100 is still displayed. But if CANNOSCALE= "1:200" then the 1:200 is displayed in the LIST command.
Ok here goesThe 1st function obtains a list of scales attached to the entity. The 2nd is a command to list the currently displayed scale.Code:;;; Function to return a list of scales attached to an entity ;;; en = the entity ename as obtained from (car entsel) (defun GetAttachedScales (en / ed d1n d1d d2n d2d d3n d3d lst dd s1d s2d n) (setq ed (entget en) ;Get entity data lst nil ;Init list to empty ) ;_ end of setq (if (and (setq d1n (cdr (assoc 360 ed))) ;Get the 1st dictionary (setq d1d (entget d1n)) ;And its data (setq d2n (cdr (assoc 360 d1d))) ;Get the 2nd dictionary (setq d2d (entget d2n)) ;And its data (setq d3n (cdr (assoc 350 d2d))) ;Get the 3rd dictionary (setq d3d (entget d3n)) ;And its data ) ;_ end of and (progn (setq dd (member (assoc 3 d3d) d3d) ;Get the portion of scales attached n 1 ;Initialize counter to 2nd item ) ;_ end of setq (while (< n (length dd)) ;Step through all items (if (= (car (nth n dd)) 350) ;Check if ACDB_ALDIMOBJECTCONTEXTDATA_CLASS ;;Get ACDB_ALDIMOBJECTCONTEXTDATA_CLASS's data (if (setq s1d (entget (cdr (nth n dd)))) ;;Get SCALE's data (if (setq s2d (entget (cdr (assoc 340 s1d)))) ;; Add to list (setq lst (cons (list (cdr (assoc 300 s2d)) ;Scale name (cdr (assoc 140 s2d)) ;Scale's 1st factor (cdr (assoc 141 s2d)) ;Scale's 2nd factor ) ;_ end of list lst ) ;_ end of cons ) ;_ end of setq ) ;_ end of if ) ;_ end of if ) ;_ end of if (setq n (+ n 2)) ;Increment counter by 2 ) ;_ end of while ) ;_ end of progn ) ;_ end of if (reverse lst) ) ;_ end of defun ;;; Command to list the currently displayed Scale (defun c:ListScale (/ en lst canno) (if (and (setq en (entsel "Select annotative entity: ")) (setq lst (GetAttachedScales (car en))) (setq canno (getvar "CANNOSCALE")) ) ;_ end of and (progn (princ "\nThe currently displayed scale is ") (if (assoc canno lst) (princ canno) (princ (car (car lst))) ) ;_ end of if ) ;_ end of progn (princ "\nThe enity doesn't have an annotative scale attached.") ) ;_ end of if (princ) ) ;_ end of defun
And here's some modifications to allow for Viewports as well ... they've only got the one Anno Scale attached (possibly) and then saved slightly different:Code:;;; Function to return a list of scales attached to an entity ;;; en = the entity ename as obtained from (car entsel) (defun GetAttachedScales (en / ed d1n d1d d2n d2d d3n d3d lst dd s1d s2d n) (setq ed (entget en) ;Get entity data lst nil ;Init list to empty ) ;_ end of setq (cond ;; If it's a viewport entity ((= (cdr (assoc 0 ed)) "VIEWPORT") (if (and (setq d1n (cdr (assoc 360 ed))) ;Get the 1st dictionary (setq d1d (entget d1n)) ;And its data (setq d2n (cdr (assoc 360 d1d))) ;Get the 2nd dictionary (setq d2d (entget d2n)) ;And its data (setq d3n (cdr (assoc 340 d2d))) ;Get the 3rd dictionary (setq d3d (entget d3n)) ;And its data ) ;_ end of and (setq lst (cons (list (cdr (assoc 300 d3d)) ;Scale name (cdr (assoc 140 d3d)) ;Scale's 1st factor (cdr (assoc 141 d3d)) ;Scale's 2nd factor ) ;_ end of list lst ) ;_ end of cons ) ;_ end of setq ) ;_ end of if ) (t (if (and (setq d1n (cdr (assoc 360 ed))) ;Get the 1st dictionary (setq d1d (entget d1n)) ;And its data (setq d2n (cdr (assoc 360 d1d))) ;Get the 2nd dictionary (setq d2d (entget d2n)) ;And its data (setq d3n (cdr (assoc 350 d2d))) ;Get the 3rd dictionary (setq d3d (entget d3n)) ;And its data ) ;_ end of and (progn (setq dd (member (assoc 3 d3d) d3d) ;Get the portion of scales attached n 1 ;Initialize counter to 2nd item ) ;_ end of setq (while (< n (length dd)) ;Step through all items (if (= (car (nth n dd)) 350) ;Check if ACDB_ALDIMOBJECTCONTEXTDATA_CLASS ;;Get ACDB_ALDIMOBJECTCONTEXTDATA_CLASS's data (if (setq s1d (entget (cdr (nth n dd)))) ;;Get SCALE's data (if (setq s2d (entget (cdr (assoc 340 s1d)))) ;; Add to list (setq lst (cons (list (cdr (assoc 300 s2d)) ;Scale name (cdr (assoc 140 s2d)) ;Scale's 1st factor (cdr (assoc 141 s2d)) ;Scale's 2nd factor ) ;_ end of list lst ) ;_ end of cons ) ;_ end of setq ) ;_ end of if ) ;_ end of if ) ;_ end of if (setq n (+ n 2)) ;Increment counter by 2 ) ;_ end of while ) ;_ end of progn ) ;_ end of if ) ) ;_ end of cond (reverse lst) ) ;_ end of defun ;;; Command to list the currently displayed Scale (defun c:ListScale (/ en lst canno) (if (setq en (entsel "Select annotative entity: ")) (if (and (setq lst (GetAttachedScales (car en))) (setq canno (getvar "CANNOSCALE")) ) ;_ end of and (progn (princ "\nThe currently displayed scale is ") (if (assoc canno lst) (princ canno) (princ (car (car lst))) ) ;_ end of if ) ;_ end of progn (princ "\nThe enity doesn't have an annotative scale attached.") ) ;_ end of if ) ;_ end of if (princ) ) ;_ end of defun