Jump to content

Create Layer with Dimension Style


rdx

Recommended Posts

Posted (edited)

Dear All,

Im Trying Create Layer with Dimension Style and selected dimension change layer name but not working properly. plase help me completed code .


(defun c:Test-11 () 
  (setvar "cmdecho" 0)
  (setvar "CELTSCALE" 3)

  ;;------------------------------------  Create Layer ----------------------------------- ;
  (if (not (tblsearch "LAYER" "TEST DIM-50")) 
    (command "_.layer" "n" "TEST DIM-50" "_color" "1" "CENTER" "_ltype" "CENTER" "CENTER" "")
  )

  ;------------------------------------

  (if (not (tblsearch "layer" "TEST DIM-100")) 
    (command "layer" "n" "TEST DIM-100" "")
  )

  ;;------------------------------------  Create Text Style  ----------------------------------- ;
  (if (not (tblsearch "STYLE" "")) 
    (progn 
      (command "STYLE" "TEST TXT-100" "ARIAL" "0" "0.7" "0" "n" "n" "n")
      (setvar "TEXTSTYLE" "TEST TXT-100")

      (command "STYLE" "TEST TXT-50" "ARIAL" "0" "0.7" "0" "n" "n" "n")
      (setvar "TEXTSTYLE" "TEST TXT-50")
    )
  )

  ;;------------------------------------  Create Dim Style (TEST DIM-100) ------------------------------------ ;;

  (if (not (tblsearch "DIMSTYLE" "TEST DIM-100")) 
    (progn 
      (setvar "DIMDLI" 2) 	; Baseline spacing
      (setvar "DIMexe" 2) 	; Beyond dimension line
      (setvar "DIMexo" 2) 	; Start offset
      (setvar "DIMASZ" 2) 	; Arrow Size
      (setvar "DIMTXT" 3) 	; Text Height
      (setvar "DIMTAD" 1) 	; Text position vertical
      (setvar "DIMJUST" 0) 	; Text Position Horizontal
      (setvar "DIMTOH" 1) 	; Text Height
      (setvar "DIMGAP" 0.3) 	; Text Offset
      (setvar "DIMATFIT" 3) 	; Text arrow adjustment options
      (setvar "DIMDEC" 1) 	; Decimal places for annotation
      (setvar "DIMLFAC" 10) 	; Scale Factor
      (setvar "DIMZIN" 8) 	; Subsequent zero elimination
      (setvar "DIMAUNIT" 1) 	; Unit format
      (setvar "DIMAZIN" 2) 	; Angle subsequent zeroing
      (setvar "DIMADEC" 5) 	; Decimal places for angle dimensioning
      (SETVAR "DIMZIN" 8) 	; Control zero elimination
      (command "DIMTXSTY" "TEST TXT-100")	;Specifies the text style of the dimension.
      (command "DIMSTYLE" "S" "TEST DIM-100")	;Creates and modifies dimension styles.
    )
  )

  ;;------------------------------------  Create Dim Style (TEST DIM-50) ------------------------------------ ;;

  (if (not (tblsearch "DIMSTYLE" "TEST DIM-50")) 
    (progn 
      (setvar "DIMDLI" 2) 	; Baseline spacing
      (setvar "DIMexe" 2) 	; Beyond dimension line
      (setvar "DIMexo" 2) 	; Start offset
      (setvar "DIMASZ" 2) 	; Arrow Size
      (setvar "DIMTXT" 3) 	; Text Height
      (setvar "DIMTAD" 1) 	; Text position vertical
      (setvar "DIMJUST" 0) 	; Text Position Horizontal
      (setvar "DIMTOH" 1) 	; Text Height
      (setvar "DIMGAP" 0.3) 	; Text Offset
      (setvar "DIMATFIT" 3) 	; Text arrow adjustment options
      (setvar "DIMDEC" 1) 	; Decimal places for annotation
      (setvar "DIMLFAC" 5) 	; Scale Factor
      (setvar "DIMZIN" 8) 	; Subsequent zero elimination
      (setvar "DIMAUNIT" 1) 	; Unit format
      (setvar "DIMAZIN" 2) 	; Angle subsequent zeroing
      (setvar "DIMADEC" 5) 	; Decimal places for angle dimensioning
      (SETVAR "DIMZIN" 8) 	; Control zero elimination
      (command "DIMTXSTY" "TEST TXT-50") 	;Specifies the text style of the dimension.
      (command "DIMSTYLE" "S" "TEST DIM-50") 	;Creates and modifies dimension styles.
    )
  )

   ;;------------------------------------  Dim Style (TEST DIM-100) ------------------------------------ ;;

  (defun C:testdim100 (/ ss n ddata) 
    (if (setq ss (ssget "_:L" '((0 . "DIMENSION")))) 
      (progn  ; then
        (command "_.chprop" ss "" "_layer" "TEST DIM-100" "")
        (repeat (setq n (sslength ss)) 
          (setq ddata (entget (ssname ss (setq n (1- n)))))
          (entmod (subst '(3 . "Annotative") (assoc 3 ddata) ddata))
        ) ; repeat
      ) ; progn
    ) ; if
  ) ; defun

  ;;------------------------------------  Dim Style (TEST DIM-50) ------------------------------------ ;;
; not wotking 
  :|
(defun C:testdim50 (/ ss n ddata) 
    (if (setq ss (ssget "_:L" '((0 . "DIMENSION")))) 
      (progn  ; then
        (command "_.chprop" ss "" "_layer" "TEST DIM-50" "")
        (repeat (setq n (sslength ss)) 
          (setq ddata (entget (ssname ss (setq n (1- n)))))
          (entmod (subst '(3 . "Annotative") (assoc 3 ddata) ddata))
        ) ; repeat
      ) ; progn
    ) ; if
  ) ; defun
|;

  ;;----------------------------------------------------------------------------------------------

  (command "DIMSTYLE" "r" "TEST DIM-100")
  (command "DIMSTYLE" "r" "TEST DIM-50")
  (setvar "cmdecho" 1)
  (princ)
)

 

 

 

Edited by rdx
Link to comment
Share on other sites

  • rdx changed the title to Create Layer with Dimension Style

You may be better using a entmake to create your style. 2 examples. You can do this as a defun for multiple dimstyles just set the variable to a value eg (cons 2 dname)

(if (not (tblsearch "dimstyle" "TA-DIM-60"))
(entmake
(list
(cons 0 "DIMSTYLE")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbDimStyleTableRecord")
(cons 2 "TA-DIM-60")
(cons 70 0)
(cons 7 "Arial")
(cons 40 1.0)
(cons 41 2.0)
(cons 46 2)
(cons 140 2.5)
(cons 340 (tblobjname "Style" "Arial"))
)
)
)

You dont have to have every single property.

(entmake
(list
(cons 0 "DIMSTYLE")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbDimStyleTableRecord")
(cons 2 Dim_Name) ;Dim style name
(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 "Standard") ; text style name
(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
)
)

 

  • Thanks 1
Link to comment
Share on other sites

You might want to load the linetype before assigning it...
Does this work better?

(defun c:Test-11 () 
  (setvar "cmdecho" 0)
  (setvar "CELTSCALE" 3)
  (if (not (tblsearch "LTYPE" "CENTER"))
    (command "_.linetype" "_load" "CENTER" "acad.lin" "")
  )
  ;;------------------------------------  Create Layer ----------------------------------- ;
  (if (not (tblsearch "LAYER" "TEST DIM-50")) 
    (command "_.layer" "_n" "TEST DIM-50" "_color" "1" "TEST DIM-50" "_ltype" "CENTER" "TEST DIM-50" "")
  )

  ;------------------------------------

  (if (not (tblsearch "layer" "TEST DIM-100")) 
    (command "_.layer" "_n" "TEST DIM-100" "")
  )

  ;;------------------------------------  Create Text Style  ----------------------------------- ;
  (if (not (tblsearch "STYLE" "")) 
    (progn 
      (command "_.STYLE" "TEST TXT-100" "ARIAL" "0" "0.7" "0" "_n" "_n")
      (setvar "TEXTSTYLE" "TEST TXT-100")

      (command "_.STYLE" "TEST TXT-50" "ARIAL" "0" "0.7" "0" "_n" "_n")
      (setvar "TEXTSTYLE" "TEST TXT-50")
    )
  )

  ;;------------------------------------  Create Dim Style (TEST DIM-100) ------------------------------------ ;;

  (if (not (tblsearch "DIMSTYLE" "TEST DIM-100")) 
    (progn 
      (setvar "DIMDLI" 2) 	; Baseline spacing
      (setvar "DIMexe" 2) 	; Beyond dimension line
      (setvar "DIMexo" 2) 	; Start offset
      (setvar "DIMASZ" 2) 	; Arrow Size
      (setvar "DIMTXT" 3) 	; Text Height
      (setvar "DIMTAD" 1) 	; Text position vertical
      (setvar "DIMJUST" 0) 	; Text Position Horizontal
      (setvar "DIMTOH" 1) 	; Text Height
      (setvar "DIMGAP" 0.3) 	; Text Offset
      (setvar "DIMATFIT" 3) 	; Text arrow adjustment options
      (setvar "DIMDEC" 1) 	; Decimal places for annotation
      (setvar "DIMLFAC" 10) 	; Scale Factor
      (setvar "DIMZIN" 8) 	; Subsequent zero elimination
      (setvar "DIMAUNIT" 1) 	; Unit format
      (setvar "DIMAZIN" 2) 	; Angle subsequent zeroing
      (setvar "DIMADEC" 5) 	; Decimal places for angle dimensioning
      (SETVAR "DIMZIN" 8) 	; Control zero elimination
      (command "_.DIMTXSTY" "TEST TXT-100")	;Specifies the text style of the dimension.
      (command "_.DIMSTYLE" "_S" "TEST DIM-100")	;Creates and modifies dimension styles.
    )
  )

  ;;------------------------------------  Create Dim Style (TEST DIM-50) ------------------------------------ ;;

  (if (not (tblsearch "DIMSTYLE" "TEST DIM-50")) 
    (progn 
      (setvar "DIMDLI" 2) 	; Baseline spacing
      (setvar "DIMexe" 2) 	; Beyond dimension line
      (setvar "DIMexo" 2) 	; Start offset
      (setvar "DIMASZ" 2) 	; Arrow Size
      (setvar "DIMTXT" 3) 	; Text Height
      (setvar "DIMTAD" 1) 	; Text position vertical
      (setvar "DIMJUST" 0) 	; Text Position Horizontal
      (setvar "DIMTOH" 1) 	; Text Height
      (setvar "DIMGAP" 0.3) 	; Text Offset
      (setvar "DIMATFIT" 3) 	; Text arrow adjustment options
      (setvar "DIMDEC" 1) 	; Decimal places for annotation
      (setvar "DIMLFAC" 5) 	; Scale Factor
      (setvar "DIMZIN" 8) 	; Subsequent zero elimination
      (setvar "DIMAUNIT" 1) 	; Unit format
      (setvar "DIMAZIN" 2) 	; Angle subsequent zeroing
      (setvar "DIMADEC" 5) 	; Decimal places for angle dimensioning
      (SETVAR "DIMZIN" 8) 	; Control zero elimination
      (command "_.DIMTXSTY" "TEST TXT-50") 	;Specifies the text style of the dimension.
      (command "_.DIMSTYLE" "_S" "TEST DIM-50") 	;Creates and modifies dimension styles.
    )
  )

   ;;------------------------------------  Dim Style (TEST DIM-100) ------------------------------------ ;;

  (defun C:testdim100 (/ ss n ddata) 
    (if (setq ss (ssget "_:L" '((0 . "DIMENSION")))) 
      (progn  ; then
        (command "_.chprop" ss "" "_layer" "TEST DIM-100" "")
        (repeat (setq n (sslength ss)) 
          (setq ddata (entget (ssname ss (setq n (1- n)))))
          (entmod (subst '(3 . "Annotative") (assoc 3 ddata) ddata))
        ) ; repeat
      ) ; progn
    ) ; if
  ) ; defun

  ;;------------------------------------  Dim Style (TEST DIM-50) ------------------------------------ ;;
; not wotking 
  :|
(defun C:testdim50 (/ ss n ddata) 
    (if (setq ss (ssget "_:L" '((0 . "DIMENSION")))) 
      (progn  ; then
        (command "_.chprop" ss "" "_layer" "TEST DIM-50" "")
        (repeat (setq n (sslength ss)) 
          (setq ddata (entget (ssname ss (setq n (1- n)))))
          (entmod (subst '(3 . "Annotative") (assoc 3 ddata) ddata))
        ) ; repeat
      ) ; progn
    ) ; if
  ) ; defun
|;

  ;;----------------------------------------------------------------------------------------------

  (command "_.DIMSTYLE" "_r" "TEST DIM-100")
  (command "_.DIMSTYLE" "_r" "TEST DIM-50")
  (setvar "cmdecho" 1)
  (princ)
)

 

Link to comment
Share on other sites

7 hours ago, BIGAL said:

You may be better using a entmake to create your style. 2 examples. You can do this as a defun for multiple dimstyles just set the variable to a value eg (cons 2 dname)

(if (not (tblsearch "dimstyle" "TA-DIM-60"))
(entmake
(list
(cons 0 "DIMSTYLE")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbDimStyleTableRecord")
(cons 2 "TA-DIM-60")
(cons 70 0)
(cons 7 "Arial")
(cons 40 1.0)
(cons 41 2.0)
(cons 46 2)
(cons 140 2.5)
(cons 340 (tblobjname "Style" "Arial"))
)
)
)

You dont have to have every single property.

(entmake
(list
(cons 0 "DIMSTYLE")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbDimStyleTableRecord")
(cons 2 Dim_Name) ;Dim style name
(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 "Standard") ; text style name
(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
)
)

 

Dear Sir,

 

Thanks 

Link to comment
Share on other sites

7 hours ago, Tsuky said:
  (if (not (tblsearch "LTYPE" "CENTER"))
    (command "_.linetype" "_load" "CENTER" "acad.lin" "")
  )

Dear Sir,

Thanks

Link to comment
Share on other sites

18 hours ago, rdx said:
  (defun C:testdim100 (/ ss n ddata) 
    (if (setq ss (ssget "_:L" '((0 . "DIMENSION")))) 
      (progn  ; then
        (command "_.chprop" ss "" "_layer" "TEST DIM-100" "")
        (repeat (setq n (sslength ss)) 
          (setq ddata (entget (ssname ss (setq n (1- n)))))
          (entmod (subst '(3 . "Annotative") (assoc 3 ddata) ddata))
        ) ; repeat
      ) ; progn
    ) ; if
  ) ; defun

Dear All.

how to add testdim50 in same function  

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...