Changing "dimension break" variable with Autolisp

Changing "dimension break" variable with Autolisp

jon.t800
Contributor Contributor
933 Views
2 Replies
Message 1 of 3

Changing "dimension break" variable with Autolisp

jon.t800
Contributor
Contributor

I was trying to create a lisp that would help me create some new dimension styles, but noticed this particular variable, dimension break, automatically becomes 3.75 for unknown reasons. Everything else seems ok. So I would like to ask if there is any simple additional lines of code I could add to ensure that value remains the same throughout the conversion. I have already tried to google this once but the one potential solution was very complicated for a novice to follow.

 

 

jont800_0-1633392654830.png

;;;ADD DIM STYLE
;;;jon's edit
;;;this program works well but pending only until I figure out why the dimension break 
;;;value under symbols and arrows is always stuck at 3.75

;--------------------------------------------------
;  MAIN ROUTINE
;--------------------------------------------------

(defun c:ad (/ *error* scale1 scale2 stylename oldstylename temp)

(command "._undo" "end" "._undo" "begin")

(setq scale1 (getvar "DIMSCALE"))
  
(setq scale1
       (cond
	 ((getreal (strcat "\nEnter primary scale: <" (rtos scale1 2 2) ">:"))) 
	  (scale1)
	  );cond. this lets me specify the prevailing value if input is ignored

)
(setq scale2
       (cond
	 ((getreal (strcat "\nEnter secondary scale: <" (rtos scale1 2 2) ">:"))) 
	  (scale1)
	  );cond. this lets me specify the prevailing value if input is ignored

)

(setq oldstylename (getvar 'DIMSTYLE))
  
(if (= scale1 scale2)
(setq stylename (strcat (substr oldstylename 1 3) "-" (rtos scale1 2 2)))
(setq stylename (strcat (substr oldstylename 1 3) "-" (rtos scale1 2 2) "-" (rtos scale2 2 2)))
);if
  
(setq temp (tblsearch "dimstyle" stylename)) ;check if existing name exists

(if (/= temp nil) (command ".-dimstyle" "save" stylename "Y") (command ".-dimstyle" "save" stylename))

(setvar "DIMSCALE" scale1)

(setvar "DIMLFAC" (/ scale2 scale1))

;POTENTIAL SOLUTION WITHIN HERE!

(command ".-dimstyle" "save" stylename "Y")

    
(princ)
(*error* nil)
)

 

0 Likes
934 Views
2 Replies
Replies (2)
Message 2 of 3

ВeekeeCZ
Consultant
Consultant

Well, there might no simple way. 

 

Anyway, here is a quick mod of idragonb's func to set and get the dimbreak style value. It returns nil for default.

 

;; by idragonb
;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-set-dimbreak-size-in-autocad-2008/m-p/4345693/highlight/true#M313626

(defun setDimBreak (dimStyleName newVal / aa qq)

  (setq ds (vla-item (vla-get-dimstyles (vla-get-activedocument (vlax-get-acad-object))) dimStyleName))			;(vlax-safearray->list aa) to see content 
                                                                                                                           ; ds contains the dimstyle object
   (vlax-invoke-method ds 'GetXData "ACAD_DSTYLE_DIMBREAK" 'aa 'qq)     ; send xdata to aa and qq
   (if aa
      (vlax-safearray-put-element qq 2 newVal)                                                ; IF XDATA EXISTS JUST MOD IT
      (progn
         (setq aa (vlax-make-safearray 2 '(0 . 2)))                                                ; vlax-vbInteger = 2
         (vlax-safearray-put-element aa 0 1001)                                                   ; dfx codes that are needed
         (vlax-safearray-put-element aa 1 1070)      
         (vlax-safearray-put-element aa 2 1040)
         (setq qq (vlax-make-safearray 12 '(0 . 2)))                                               ; create array of vlax-vbVariant = 12
         (vlax-safearray-put-element qq 0 "ACAD_DSTYLE_DIMBREAK")            ; app
         (vlax-safearray-put-element qq 1 391)                                                      
         (vlax-safearray-put-element qq 2 newVal)))                                               ; HERE'S THE DATA
   (vlax-invoke-method ds 'SetXData aa qq)                                                        ; throw it back in
)

;; beekee
(defun getDimBreak (dimStyleName / aa qq)
  
   (vlax-invoke-method
     (vla-item (vla-get-dimstyles (vla-get-activedocument (vlax-get-acad-object))) dimStyleName)
     'GetXData "ACAD_DSTYLE_DIMBREAK" 'aa 'qq)     ; send xdata to aa and qq
   (if aa
     (vlax-variant-value (vlax-safearray-get-element qq 2))))

 

0 Likes
Message 3 of 3

Sea-Haven
Mentor
Mentor

I think it can be done using entmake and adding the xdata to the entmake, had similar problem with arrows. Beyond my pay rate so no code. (cons 1001 xdata) ?? The dxf codes needed are in post above. Just dont know how to use them in entmake dim.

0 Likes