Author Topic: Any idea how can I parse through all dimension lines from a layer  (Read 2941 times)

0 Members and 1 Guest are viewing this topic.

paulipsum

  • Guest
Hello everyone, I am a newbie and I am trying to write a small program to go through all my dimension lines and modify scale factor to some of them. For example if a dimension is larger than 100cm  I want it to be displayed in meters so I want to divide it to 100. Thank you for any information! :-o

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Any idea how can I parse through all dimension lines from a layer
« Reply #1 on: December 20, 2014, 03:22:14 AM »

Firstly Scale has nothing to do with the dimension text value.

You will need to override the text value with modified text.

Personally I wouldn't like to have to read ( or edit ) the drawings that had been modified as you intend.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Any idea how can I parse through all dimension lines from a layer
« Reply #2 on: December 20, 2014, 06:46:27 AM »
Strange is it may seem what the OP wants is standard for German architectural drawings and there are developers who have made quite a buck selling reactor based programs to accomplish this.

paulipsum

  • Guest
Re: Any idea how can I parse through all dimension lines from a layer
« Reply #3 on: December 20, 2014, 08:37:53 AM »

Firstly Scale has nothing to do with the dimension text value.

You will need to override the text value with modified text.
Dear Kerry thank you for helping me. I know how to override the scale but I don't know how to select all dimension entities and introduce the IF instance or create another dimension style and auto switch it.
Strange is it may seem what the OP wants is standard for German architectural drawings and there are developers who have made quite a buck selling reactor based programs to accomplish this.

Dear Roy, I am also from EU, however in my country you can draw all dimensions in cm and specify at the bottom that all dimensions are in cm, this is the case for reinforced concrete. I don't consider that there is too much code to accomplish what I need.

Wish you both nice Christmas holidays!

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Any idea how can I parse through all dimension lines from a layer
« Reply #4 on: December 20, 2014, 02:44:10 PM »
@paulipsum
>>> I know how to override the scale < ... >

I'm interested in what you mean by this and how you achieve it.

Do you suffix changed dimensions  ( for example 120 will become 1.20M ) ?

Here in Australia it is common to use MM only typically for the type of work you are targeting.
It's difficult to confuse 12 and 120 and 12000
« Last Edit: December 20, 2014, 02:47:35 PM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

paulipsum

  • Guest
Re: Any idea how can I parse through all dimension lines from a layer
« Reply #5 on: December 21, 2014, 03:58:30 AM »
I'm interested in what you mean by this and how you achieve it.

I found some code which cycles through dimension styles
Code: [Select]
(defun c:styl (/ sty)
    (setq Old_cmdecho (getvar "cmdecho"))
  (setvar "cmdecho" 0)
;; getting first dimstyle created
  (setq sty (tblnext "DIMSTYLE"))
  ;; getting dimstyle name
  (setq sty(cdr (assoc 2 sty)))
  (while  (/= sty nil) ;; if dimstyle is not nil then proceed
  (setq sty(tblsearch "DIMSTYLE" sty)) ;; searching dimstyle dialog box for dimstyle name
  (if (= (cdr (assoc 2 sty)) "Standard");; if the dimstyle name equals standard then go to the next dimstyle and get its name
    (progn
      (setq sty (tblnext "DIMSTYLE"))
      (setq sty(cdr (assoc 2 sty)))
      );; end of progn
    (progn
  (setvar "dimscale" 2);; If the dimstyle name is not Standard then set the dimscale to 2
  (command "-dimstyle" "s" (cdr (assoc 2 sty)) "y");; save the newly created dimstyle with the same name and new dimscale
  (setq sty (tblnext "DIMSTYLE"));;Get the next dimstyle
  (setq sty(cdr (assoc 2 sty)));; Get dimstyle name and repeat while until value is nil
    );; end of progn
  );; end of if
);; end of while

    (setvar "cmdecho" Old_cmdecho);; when value is nil reset the cmdecho variable to its original value
  (princ)
)
(prompt "******* To run the program type STYL at the command prompt*******")

but is not quite what I need, because it doesn't cycle through every dimension. The code I want to introduce is
Code: [Select]
(IF (> DIST 100) 
(setq dist (/ dist 100) )

(SETQ dist dist))

Entities are like objects in C? How can I point to entity's properties like length, dimension or style, (I am referring to dimension lines of course type of objects)
Here mm are used only for steel works, in construction design.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Any idea how can I parse through all dimension lines from a layer
« Reply #6 on: December 21, 2014, 08:14:57 AM »
Try this draft and let me know . (hope that I got you right )  :wink:

NOTE: you can change the decimal numbers if you change the indicated number as shown in the routine .

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ *error* sel m dz)
  2.   ;;    Tharwat 21.12.2014              ;;
  3.   (defun *error* (msg)
  4.     (if dz
  5.       (setvar 'DIMZIN dz)
  6.     )
  7.     (if (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")
  8.       (princ (strcat "\n** Error: " msg " **"))
  9.     )
  10.     (princ)
  11.   )
  12.   (setq dz (getvar 'DIMZIN))
  13.   (setvar 'DIMZIN 0)
  14.   (princ "\n Select Dimensions to divide on 100. units ")
  15.   (if (ssget "_:L" '((0 . "*DIMENSION")))
  16.     (vlax-for dim
  17.               (setq
  18.                 sel (vla-get-ActiveSelectionSet
  19.                       (vla-get-ActiveDocument (vlax-get-acad-object))
  20.                     )
  21.               )
  22.       (if (> (setq m (vla-get-measurement dim)) 100.)
  23.         (vla-put-TextOverride dim (rtos (/ m 100.) 2 3)) ;; Change the number 3 which is represent the number of decimal number to suit your needs
  24.       )
  25.     )
  26.   )
  27.   (if sel
  28.     (vla-delete sel)
  29.   )
  30.   (*error* nil)
  31.   (princ)
  32.  

paulipsum

  • Guest
Re: Any idea how can I parse through all dimension lines from a layer
« Reply #7 on: December 26, 2014, 10:28:41 AM »
Tharwat you are the best, the code works like charm. Thank you very much and have a nice holiday.

Try this draft and let me know . (hope that I got you right )  :wink:

NOTE: you can change the decimal numbers if you change the indicated number as shown in the routine .


mailmaverick

  • Bull Frog
  • Posts: 493
Re: Any idea how can I parse through all dimension lines from a layer
« Reply #8 on: December 26, 2014, 11:16:14 AM »
My take :

Code: [Select]

(defun c:Test (/ *error* sel m dz)
  (vl-load-com)
  ;; Tharwat 21.12.2014 ;;
  (defun *error* (msg)
    (if dz
      (setvar 'DIMZIN dz)
    )
    (if (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")
      (princ (strcat "\n** Error: " msg " **"))
    )
    (princ)
  )
  (setq dz (getvar 'DIMZIN))
  (setvar 'DIMZIN 0)
  (princ "\n Select Dimensions to divide on 100. units ")
  (if (ssget "_:L" '((0 . "*DIMENSION")))
    (vlax-for dim (setq sel (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object))))
      (if (> (setq m (vla-get-measurement dim)) 100.)
(progn (vla-put-LinearScaleFactor dim 0.001)
       ;; Above command scales the dimension by 1/1000
       (vla-put-TextSuffix dim "m")
       ;; Above command adds Suffix "m" to text
       (vla-put-PrimaryUnitsPrecision dim 0.00)
       ;; Above command sets the precision to 2 digits. You can change the precision according to following options :-
       ;; Options : 0. ; 0.0 ; 0.00 ; 0.000 ; 0.0000 ; 0.00000 ; 0.000000 ; 0.0000000 and 0.00000000
       (vla-Update dim)
       ;; Above command updates the dimension according to above changes
)
      )
    )
  )
  (if sel
    (vla-delete sel)
  )
 (*error* nil)
  (princ)
)

The above routine is better because it does not override the text. It just adds changes scale, adds suffix and sets precision.
« Last Edit: December 26, 2014, 12:10:50 PM by mailmaverick »

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Any idea how can I parse through all dimension lines from a layer
« Reply #9 on: December 26, 2014, 12:16:29 PM »
Tharwat you are the best, the code works like charm. Thank you very much and have a nice holiday.

Excellent , you are most welcome .