Loading My Company Dimenstion Styles from LISP

Loading My Company Dimenstion Styles from LISP

Todd_Rogers
Mentor Mentor
1,137 Views
14 Replies
Message 1 of 15

Loading My Company Dimenstion Styles from LISP

Todd_Rogers
Mentor
Mentor

So, I have a button to set up my text styles in case they get purged from a drawing. See below...

 

;; Load all Core Fonts
;;
(defun c:corefonts ()
(setq expert (getvar "expert")) (setvar "expert" 5)
; (command "-style" "H" "hlvm.shx" "0" "1" "0" "no" "no")
(command "-style" "Symbol" "symap.shx" "0" "1" "0" "no" "no" "no")
; (command "-style" "R-Oblique" "RomanS" "0" "1" "15" "" "" "")
(command "-style" "Street Names" "Calibri.TTF" "0" "1" "0" "no" "no")
; (command "-style" "R" "RomanS" "0" "0.8" "0" "no" "no" "no")
; (command "-style" "Annotative" "Calibri.TTF" "Annotative" "yes" "no" "0.1" "1" "0" "no" "no" "no")
; (command "-style" "Arial" "Calibri.TTF" "0" "1" "0" "" "" "")
(command "-style" "CORE-OBLIQUE" "Calibri.TTF" "0" "1" "15" "" "" "")
(command "-style" "CORE-STANDARD" "Calibri.TTF" "0" "1" "0" "" "" "")
(setvar "expert" expert)
(command "regenall")
)

 

I want to do the same with my dimension styles. Would I use the same format, but with -dimstyle?

Todd Rogers
Civil Administration at Walter P Moore
0 Likes
Accepted solutions (2)
1,138 Views
14 Replies
Replies (14)
Message 2 of 15

pendean
Community Legend
Community Legend

@Todd_Rogers wrote:

...I want to do the same with my dimension styles. Would I use the same format, but with -dimstyle?


Indeed it would be that as a solution, if a drag-and-drop of a block with all of those dimension styles in it is not working well or a transfer using ADCENTER (or stating with a template file) are not ideal.

Message 3 of 15

Todd_Rogers
Mentor
Mentor

Yeah, I'm testing it right now. The hang up I'm getting is, when I purge out the dimstyles, I can't figure out where to pull them from to reload them in the drawing. I assume I need to call the template file somehow.

Todd Rogers
Civil Administration at Walter P Moore
0 Likes
Message 4 of 15

Todd_Rogers
Mentor
Mentor

Looks like I have to create the lisp to actually just recreate the dimstyle. UGH!

Todd Rogers
Civil Administration at Walter P Moore
0 Likes
Message 5 of 15

hak_vz
Advisor
Advisor

@Todd_Rogers 

You have to export dimension style variables to reuse it. To do so start dimension style manager (dimstyle), select on you want to export and set it as current. Press compare button  and in popup under compare and with option select same dimension style. As you do so dimension values  for that style will show up.

dimstyle manager.png

 Use copy button next to the table and copy values to clipboard and paste it to some txt file. Here you have list of all DIM*** system variables related to that dimension style. 

For particular dimension style you can have ....

(defun c:create_base_style()
    (setvar "DIMALTD" 4)
    (setvar "DIMALTF" 1)
    (setvar "DIMALTTD" 4)
    (setvar "DIMALTU" 4)
    (setvar "DIMADEC" 1)
    (setvar "DIMAZIN" 0)
    (setvar "DIMARCSYM" 1)
    (setvar "DIMASZ" 1)
    (setvar "DIMCEN" 0)
    (setvar "DIMCLRD" 3)
.....

    (command "dimstyle" "s" "base_style")

    (princ)
)

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 6 of 15

Todd_Rogers
Mentor
Mentor

That's what I did yesterday. Below is what I have so far, but it seems to not be working...

 

;; Load all Core Dimension Styles
;; Created by TODD ROGERS 7/19/2023
;;
(defun COREDIMS ()
(if (= (tblsearch "DIMSTYLE" "CORE-PARKING-8.5") nil)
(progn
(princ (strcat "\nDimension style '" CORE-PARKING-8.5 "' already exists."))
(prompt "\nPress Enter to continue.")
)
(progn
(command "DIMSTYLE" "S" "CORE-PARKING-8.5")
(command "DIM"
"DIMSCALE" 20.0 ; Dimension scale factor
"DIMLUNIT" 2 ; Sets units for all dimensions
"DIMANNO" 0 ; Annotative
"DIMBLK" "" ; Arrowhead style closed filled
"DIMASZ" 0.18 ; Arrowhead size
"DIMCLRD" 256 ; Dimension line color
"DIMCLRE" 256 ; Extension line color
"DIMCLRT" 256 ; Text color
"DIMLWD" -2 ; Dimension line lineweight
"DIMLWE" -2 ; Extension line lineweight
"DIMGAP" 0.125 ; Dimension break
"DIMTIH" 0 ; Text aligned with dimension line
"DIMTAD" 1 ; Text above dimension line
"DIMJUST" 0 ; Dimension text justification
"DIMEXO" 0.05 ; Extension line offset
"DIMEXE" 0.05 ; Extension beyond dimension line
"DIMDLE" 0 ; Dimension line extension
"DIMRND" 0 ; Rounding value
"DIMTXSTY" "CORE-STANDARD" ; Text style
"DIMTXT" 0.1 ; Text height
"DIMCEN" 0 ; Center mark style
"DIMTSZ" 0.18 ; Dimension text size
"DIMLFAC" 1.0 ; Linear scale factor
"DIMASO" 2 ; Associative object display
"DIMTIX" 1 ; Force text inside extensions
"DIMSOXD" 0 ; Suppress outside extensions
"DIMALT" 1 ; Enables alternate units
"DIMALTD" 1 ; Alternate units precision
"DIMALTF" 8.5 ; Multiplier for alt units
"DIMALTRND" 0.5 ; Alt units multiplier rounding
"DIMALTZ" 8 ; Alt units for zero suppression
"DIMAPOST" ; SPA @ 8.5'= ; Alt units prefix/suffix
"DIMARCSYM" 0 ; Arc symbol
"DIMATFIT" 0 ; Dimension fit outside extension lines
"DIMAUNIT" 0 ; Dimension unit decimal
"DIMDEC" 1 ; Primary units precision

)
(princ (strcat "\nDimension style '" CORE-PARKING-8.5 "' created."))
(prompt "\nPress Enter to continue.")
)
)
)

 

Todd Rogers
Civil Administration at Walter P Moore
0 Likes
Message 7 of 15

Kent1Cooper
Consultant
Consultant
Accepted solution

You have it telling the User that the Style already exists only when it doesn't.  And the formatting to show the double-quotes in that message is incorrect.  And you need to Save it after setting the variables.  And I would use (setvar) rather than all those things as commands.  Also, (alert) rather than (princ) [or I would have used (prompt)] carries with it its own "Enter to continue" idea in its OK button.

 

Shouldn't it be more like:

 

(if (tblsearch "DIMSTYLE" "CORE-PARKING-8.5")

  (alert "\nDimension style \"CORE-PARKING-8.5\" already exists."); then

  (progn ; else

    (setvar 'dimscale 20.0) ; Dimension scale factor
     .... ;;;  etc., etc.

    (setvar 'dimdec 1) ; Primary units precision

    (command "_.dimstyle" "_save" "CORE-PARKING-8.5")

    (alert "\nDimension style \"CORE-PARKING-8.5\" created.")

  ); progn [else]

); if

 

Or, if you want to force values for the Style even if it already exists, to update it in case it's not according to current standards, it would be structured differently:

 

(if (tblsearch "DIMSTYLE" "CORE-PARKING-8.5")

  (alert "\nDimension style \"CORE-PARKING-8.5\" already exists -- updating."); then

); if

;; then regardless of whether or not it exists already:

(setvar 'dimscale 20.0) ; Dimension scale factor
.... ;;;  etc., etc.

(setvar 'dimdec 1) ; Primary units precision

(command "_.dimstyle" "_save" "CORE-PARKING-8.5")

(if (tblsearch "DIMSTYLE" "CORE-PARKING-8.5") (command "_yes"))

(alert

  (strcat

    "\nDimension style \"CORE-PARKING-8.5\" "

    (if (tblsearch "DIMSTYLE" "CORE-PARKING-8.5") "updated." "created.")

  ); strcat

); alert

Kent Cooper, AIA
Message 8 of 15

hak_vz
Advisor
Advisor
Accepted solution

@Todd_Rogers   I've edited your lisp, and it now works ok.

Before setting dimtext style and other values that are commented they have to be defined. Text style before dimstyle text .....

 

(defun COREDIMS ()
	(if (and (tblsearch "DIMSTYLE" "CORE-PARKING-8.5"))
		(progn
			(princ "\nDimension style CORE-PARKING-8.5 already exists.")
		)
		(progn
			(setvar 'DIMSCALE 20.0 ); Dimension scale factor
			(setvar 'DIMLUNIT 2 ); Sets units for all dimensions
			;(setvar 'DIMANNO 0 ); Annotative
			(setvar 'DIMBLK  ""); Arrowhead style closed filled
			(setvar 'DIMASZ 0.18 ); Arrowhead size
			(setvar 'DIMCLRD 256 ); Dimension line color
			(setvar 'DIMCLRE 256 ); Extension line color
			(setvar 'DIMCLRT 256 ); Text color
			(setvar 'DIMLWD -2 ); Dimension line lineweight
			(setvar 'DIMLWE -2 ); Extension line lineweight
			(setvar 'DIMGAP 0.125 ); Dimension break
			(setvar 'DIMTIH 0 ); Text aligned with dimension line
			(setvar 'DIMTAD 1 ); Text above dimension line
			(setvar 'DIMJUST 0 ); Dimension text justification
			(setvar 'DIMEXO 0.05 ); Extension line offset
			(setvar 'DIMEXE 0.05 ); Extension beyond dimension line
			(setvar 'DIMDLE 0 ); Dimension line extension
			(setvar 'DIMRND 0 ); Rounding value
			;(setvar 'DIMTXSTY "CORE-STANDARD" ); Text style
			(setvar 'DIMTXT 0.1 ); Text height
			(setvar 'DIMCEN 0 ); Center mark style
			(setvar 'DIMTSZ 0.18 ); Dimension text size
			(setvar 'DIMLFAC 1.0 ); Linear scale factor
			;(setvar 'DIMASO 2 ); Associative object display
			(setvar 'DIMTIX 1 ); Force text inside extensions
			(setvar 'DIMSOXD 0 ); Suppress outside extensions
			(setvar 'DIMALT 1 ); Enables alternate units
			(setvar 'DIMALTD 1 ); Alternate units precision
			(setvar 'DIMALTF 8.5 ); Multiplier for alt units
			(setvar 'DIMALTRND 0.5 ); Alt units multiplier rounding
			(setvar 'DIMALTZ 8 ); Alt units for zero suppression
			;(setvar 'DIMAPOST SPA @ 8.5'=);  ); Alt units prefix/suffix
			(setvar 'DIMARCSYM 0 ); Arc symbol
			(setvar 'DIMATFIT 0 ); Dimension fit outside extension lines
			(setvar 'DIMAUNIT 0 ); Dimension unit decimal
			(setvar 'DIMDEC 1 ); Primary units precision
			(command "DIMSTYLE" "S" "CORE-PARKING-8.5")
			(princ "\nDimension style CORE-PARKING-8.5 created.")
		)
	)
	(princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 9 of 15

Kent1Cooper
Consultant
Consultant

@hak_vz wrote:

.....

(defun COREDIMS ()
	(if (and (tblsearch "DIMSTYLE" "CORE-PARKING-8.5"))
		(progn
			(princ "\nDimension style CORE-PARKING-8.5 already exists.")
		)
		(progn
			(setvar 'DIMSCALE 20.0 ); Dimension scale factor
....

Neither that (and) nor that first (progn) wrapper around the (princ) function is doing anything for you, or am I missing something?

Kent Cooper, AIA
Message 10 of 15

hak_vz
Advisor
Advisor

@Kent1Cooper wrote:

Neither that (and) nor that first (progn) wrapper around the (princ) function is doing anything for you, or am I missing something?

Not needed, remains from OP original code.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 11 of 15

Todd_Rogers
Mentor
Mentor

Thanks guys. It's been years since I have wrote a lisp routine. Trying to get back in the groove again.

Todd Rogers
Civil Administration at Walter P Moore
0 Likes
Message 12 of 15

Todd_Rogers
Mentor
Mentor

Since DIMANNO is Read-Only, how do you set the style to annotative, or not annotative?

Todd Rogers
Civil Administration at Walter P Moore
0 Likes
Message 13 of 15

Sea-Haven
Mentor
Mentor

Maybe something like this remove unwanted cons. For multiple can have a list of styles and values to set. Forget where I got it.

 

 

(if (not (tblsearch "dimstyle" "DIM-50"))
(entmake
(list
(cons 0 "DIMSTYLE")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbDimStyleTableRecord")
(cons 2 Dim_Name) ;Dim style name eg "DIM-50"
(cons 70 0) ; Standard flag
(cons 3 " [m]"); DIMPOST
(cons 4 ""); DIMAPOST
(cons 5 DIMBLK-Name) ;DIMBLK-Name of block instead of default arrowhead
(cons 6 DIMBLK-Name);(cons 6 "ClosedFilled"); DIMBLK1
(cons 7 "");(cons 7 DIMBLK-Name); DIMBLK2
(cons 170 0) ;DIMALT-turns off alternate units
(cons 40 dimscale) ;DIMSCALE-sets the overall scale factor applied to all dimensions
(cons 41 Arrow_Size) ;DIMASZ-sets the size of the arrow/tick
(cons 42 Extension_Line_Origin_Offset); DIMEXO
(cons 43 Dimension_Line_Spacing); DIMDLI
(cons 44 Extension_Above_Dimension_Line) ;DIMEXE-specifies how far to extend the extention line beyound the dim line
(cons 45 0.0); DIMRND
(cons 46 0) ;DIMDLE-sets the distance the dimension line extends beyond the extension line
(cons 47 0.0); DIMTP
(cons 48 0.0); DIMTM
(cons 71 0); DIMTOL
(cons 72 0); DIMLIM
(cons 73 0) ;DIMTIH-controls the position of dimension text inside extention lines ;METTE IL TESTO DI QUOTA ORIZZONTALE
(cons 74 0) ;DIMTOH-controls the position of dimension text outside extention lines
(cons 75 1); DIMSE1 ;1 sopprime la linea di estensione, 0 la lascia
(cons 76 1); DIMSE2 ;1 sopprime la linea di estensione, 0 la lascia
(cons 77 1) ;DIMTAD-controls the vertical position of text in relation to the dim line
(cons 78 3) ;DIMZIN-controls the suppression of zeros
(cons 79 1); DIMAZIN
(cons 140 Text_Height) ;DIMTXT-specifies the height of the text in the dim
(cons 141 Center_Mark_Size); DIMCEN
(cons 142 0.0); DIMTSZ
(cons 143 0.5) ;DIMALTF-controls the scale factor for alt. units
(cons 144 quote_scale); DIMLFAC ;scala di quota
(cons 145 0.0); DIMTVP
(cons 146 0.64); DIMTFAC
(cons 147 Gap_From_dimension_Line_to_Text) ;DIMGAP-sets the distance from around the dim text
(cons 170 0); DIMALT
(cons 171 2) ;DIMALTD-controls the decimal places for units
(cons 172 0) ;DIMTOFL-forces a line inside extension lines
(cons 173 1); DIMSAH
(cons 174 0); DIMTIX
(cons 175 0); DIMSOXD
(cons 176 256); DIMCLRD
(cons 177 256); DIMCLRE
(cons 178 256); DIMCLRT color of text 
(cons 179 0); DIMADEC
(cons 270 2) ;DIMUNIT-sets the units format for all dims ;2 decimale ; 4architettonico
(cons 271 Decimal_Places) ;DIMDEC-sets the number of decimal places of primary units
(cons 272 Tolerance_Decimal_places); DIMTDEC
(cons 273 2) ;DIMALTU-sets the units for alt. units
(cons 275 0) ;DIMAUNIT-sets the angular format for angular dims
(cons 276 1); DIMFRAC
(cons 277 2); DIMLUNIT ;2 decimale ; 4architettonico
(cons 278 0); DIMDSEP
(cons 279 Text_Movement); DIMTMOVE
(cons 280 0) ;DIMJUST-controls the horizontal positioning of dim text
(cons 281 -1); DIMSD1
(cons 282 -1); DIMSD2
(cons 283 1); DIMTOLJ
(cons 284 3); DIMTZIN
(cons 285 1); DIMALTZ
(cons 286 0) ;DIMALTTZ-Toggles the suppression in tolerance values
;(cons 287 0); DIMFIT
;(cons 288 0); DIMUPT
;(cons 289 0); DIMATFIT
(cons 340 (tblobjname "style" "Estilo_Cotas")); DIMTXSTY
;(cons 341 (cdr (assoc 330 (entget (tblobjname "block" "."))))); DIMLDRBLK 
;(cons 342 (cdr (assoc 330 (entget(tblobjname "block" "_Oblique"))))); DIMBLK must setvar dimblk 1st 
;(cons 343 (cdr (assoc 330 (entget(tblobjname "block" "_Oblique"))))); DIMBLK1
;(cons 344 (cdr (assoc 330 (entget(tblobjname "block" "_Oblique"))))); DIMBLK2
;(cons 371 -2); DIMLWD
;(cons 372 -2); DIMLWE
)
)
)

 

 

Message 14 of 15

Tall_pkirkendall
Participant
Participant

We just use a script that gets called from a ribbon button (or tool palette). The script calls for an insert of the template file as a block then explodes it so all the style get put back in the current file. Something like below.

 

filedia
0
cmddia
0
-insert
companytemplate.dwg
0,0
1
1
0
explode
l
filedia
1
cmddia
1

Message 15 of 15

Sea-Haven
Mentor
Mentor

Another, look at Steal.lsp by Lee-mac.com very easy to get stuff from another dwg. You can program it to run what you want maybe 6 lines of code in total as you load Lee's program if not loaded already. Then call the defun.

0 Likes