TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: lamarn on June 16, 2016, 06:46:01 AM

Title: how to override all dimension lines DIMLTEX
Post by: lamarn on June 16, 2016, 06:46:01 AM
Hi

What ways are there to override the value of DIMLTEX1 and DIMLTEX2
The idea is to change, on request, ALL dimension lines regardless of the style to dotted
To setlect them i use

(setq ss1 (ssget "X" '((0 . "dimension"))))

But then?..maybe parts a method like this one?

https://www.theswamp.org/index.php?topic=12623.0

thanks anyway
Title: Re: how to override all dimension lines DIMLTEX
Post by: mailmaverick on June 16, 2016, 10:12:23 AM
Try the following code :
Code: [Select]
;; Load all LineTypes in AutoCAD
;; Check for presence of DOT linetype
;; If present, change extension lines of all dimension objects to DOT
;;
(defun c:test (/ ltobj LTNM ENT FOUND N OBJ SS1 CNT)
  (vl-load-com)
  (defun _loadAllLinetypes (linFile)
    ;; Credit to ALANJT
    ;; Source : http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/load-line-types-with-lisp/td-p/4305876
    (if (setq linFile (findfile linFile))
      (progn (command "_.-linetype" "_l" "*" linFile)
             (while (eq (logand 1 (getvar 'CMDACTIVE)) 1) (command ""))
             T
      )
    )
  )
  ;; Load all linetypes
  (_loadAllLinetypes "acad.lin")
  (_loadAllLinetypes "acadiso.lin")
  (setq found nil)
  ;;
  ;; Check availability of DOT linetype
  (vlax-for ltobj (vla-get-linetypes (vla-get-activedocument (vlax-get-acad-object)))
    (if (vlax-property-available-p ltobj 'Name nil)
      (progn (setq LTNM (strcase (vlax-get-property ltobj 'Name)))
             (if (equal LTNM "DOT")
               (setq found T)
             )
      )
    )
  )
  ;;
  ;; If Found then Put Linetype as DOT to Ext Line of all dimensions
  (if found
    (progn (if (setq ss1 (ssget "_X" (list (cons 410 "MODEL") (cons 0 "*DIMENSION"))))
             (progn (setq cnt 0)
                    (repeat (setq n (sslength ss1))
                      (setq ent (ssname ss1 (setq n (1- n))))
                      (setq obj (vlax-ename->vla-object ent))
                      (if (vlax-property-available-p obj 'extline1linetype nil)
                        ;; This check is necessary because certain dimensions may not have this property
                        (progn (vla-put-extline2linetype obj "DOT")
                               (vla-put-extline1linetype obj "DOT")
                               (setq cnt (1+ cnt))
                        )
                      )
                    )
                    (princ (strcat "\nLinetype changed to DOT for "
                                   (itoa cnt)
                                   " dimensions out of total "
                                   (itoa (sslength ss1))
                                   " dimensions."
                           )
                    )
             )
             (progn (princ "\nNo dimension objects found."))
           )
    )
    (progn (princ "\nCound not find DOT linetype."))
  )
  (princ)
)
Title: Re: how to override all dimension lines DIMLTEX
Post by: PKENEWELL on June 16, 2016, 10:29:03 AM
Here's my solution just using (command):

Code: [Select]
;; By pkenewell 6/16/2016

(defun c:DIMEXTDOT (/ doc lts dl1 dl2 lt lf ss)

   (setq doc (vla-get-activedocument (vlax-get-acad-object))
         lts (vla-get-linetypes doc)
         dl1 (getvar "dimltex1")
         dl2 (getvar "dimltex2")

         ;; Change these below for different linetype and file
         lt "DOT"
         lf "ACAD.LIN"
   )

   (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list lts lt)))
      (vla-load lts lt lf)
   )

   (if (setq ss (ssget "X" '((0 . "DIMENSION"))))
      (progn
         (setvar "dimltex1" lt)
         (setvar "dimltex2" lt)
         (command "._-dimstyle" "_A" ss "")
         (setvar "dimltex1" dl1)
         (setvar "dimltex2" dl2)
      )
   )
   (princ)
)

EDIT: Added a bit of code to reset the dimvars when finished. Also localized variables
Title: Re: how to override all dimension lines DIMLTEX
Post by: lamarn on June 16, 2016, 04:36:18 PM
Thanks ! Great help for me
I tried them both but found DIMEXTDOT to give a error run from paperspace (nothing found probably).
This routine is a nice one to have for scripting DWG's to get to a certain look.
Please have a look at this one for its use

<iframe width="560" height="315" src="https://www.youtube.com/embed/qX4a8CTGIGs" frameborder="0" allowfullscreen></iframe>
Title: Re: how to override all dimension lines DIMLTEX
Post by: Grrr1337 on June 17, 2016, 04:24:38 PM
Great idea, halam!
And thanks for posting this code, mailmaverick!.. finally fixed my "load linetypes" issue in some other codes of mine.
Title: Re: how to override all dimension lines DIMLTEX
Post by: lamarn on June 18, 2016, 07:41:15 AM
Yes grrr. Main purpose is for updating dwg from Revit with script.
I had a linetype loader based on a -vbarun routine with nasty errors and slow loading
Learning this is a nice side effect ;-)

(defun _loadAllLinetypes (linFile)
    ;; Credit to ALANJT
    ;; Source : http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/load-line-types-with-lisp/td-p/4305876
    (if (setq linFile (findfile linFile))
      (progn (command "_.-linetype" "_l" "*" linFile)

Or did you mean something else?

Title: Re: how to override all dimension lines DIMLTEX
Post by: PKENEWELL on June 20, 2016, 01:15:01 PM
Thanks ! Great help for me
I tried them both but found DIMEXTDOT to give a error run from paperspace (nothing found probably).
This routine is a nice one to have for scripting DWG's to get to a certain look.
Please have a look at this one for its use

<iframe width="560" height="315" src="https://www.youtube.com/embed/qX4a8CTGIGs" frameborder="0" allowfullscreen></iframe>

Yes - All you would have to do is add the (410 . "MODEL") filter to my ssget statement for it to be the same as mailmaverick's.