Jump to content

Another dimstyle creation question


KGehrels

Recommended Posts

HI

I have already read through a bunch of dimstyle threads and am continuing to do so.  However, my boss is breathing down my neck so I need to get the code finished and am hoping that someone here will help.

 

I'm working with drawings that have a large number of unnecessary dimstyles (15 or more).  What I'm working on is code to find the different scales that are used and make a linear and diametric dimstyle for each scale (linear built off of Standard and diametric built off of linear), apply the new styles to all existing dimensions and purging the old styles.  I've been able to build the code that goes through all existing dimstyles, make a list of the scales and remove all duplicates from the list. 

 

Now I'm trying to make the new dimstyles.  My understanding is that the way to do this is use the vla-copyfrom code.  My intension is to start with the Standard dimstyle as this is a stable base to build from and modify the system variables from there.  Here's where my understanding falls apart. 

  • For some reason I can't get vla-put-activedimstyle to accept "Standard" as an input.
  • So I'm trying to use vla-copyfrom right away to create the linear dimstyle then use vla-put-activedimstyle to make the new dimstyle the active style.
  • Then I'm running a list of setvar's that don't work for whatever reason (error: bad argument type: VLA-OBJECT "Linear-1")
  • Should the code get this far I've got it set to try and save the new dimstyle over itself...I'm not sure this will work. 
    • If it doesn't I figure that I can make a dummy code, apply all changes to it then save it under the desired name.
  • Then I want to run through a similar set of steps for the Diametric style

 

Thanks for any help that comes my way.

(defun c:Create_dimstyles ( / acadObj doc styleset stylecount scalelist stylecount style stylescale scale unique-scalelist currentDimStyle)
  (vl-load-com)
  (setq acadObj (vlax-get-acad-object))
  (setq doc (vla-get-activedocument acadObj))
  
  (setq styleset (vla-get-DimStyles doc)); Gets all dimstyles in the active document
  (setq stylecount (vla-get-count styleset))
  (setq scalelist '()); Creates an empty list
    
  (if (> stylecount 1); Checks if there is more than one dimstyle
    (progn
      (vlax-for style styleset; Finds the scale of each dimstyle and adds it to the beginning of scalelist
        (vla-put-activedimstyle doc style); Makes the active dimstyle
        (setq stylescale (GetVar "DimLFac")); Gets the scale of the active dimstyle
        (setq scalelist (cons stylescale scalelist)); Adds the scale to scalelist
      ); End vlax for
      (setq scalelist (vl-sort scalelist '<)); Sorts the scales from smallest to largest
      (setq unique-scalelist '())
      (foreach scale scalelist; removes duplicates
        (if (not (member scale unique-scalelist))
          (setq unique-scalelist (cons scale unique-scalelist))
        ); end if
      ); foreach
      (setq scalelist (reverse unique-scalelist)); rea
    ); end progn
  ); End if
  
  ;prints are for error checking
  (princ (strcat "# of styles: " (itoa stylecount)))
  (print)
  (princ "List of scales: ")
  (foreach scale scalelist
    (princ(strcat (rtos scale 2 2) ", "))
  ); end foreach
  ;prints are for error checking
  
  (foreach scale scalelist
    ;Create Linear dimstyles
    (vla-copyfrom (strcat "Linear-" (rtos scale 2 2)) "Standard"); Create a new dimstyle called "Linear-" with the scale as a suffix
    (vla-put-activedimstyle doc (strcat "Linear-" (rtos scale 2 2))); Make the new dimstyle the active style
    
    ;Modify the new Linear dimstyle
    (setvar "DIMASZ" 0.130) ; Arrow size
    (setvar "DIMCLRD" "ByLayer"); Dimension line colour
    (setvar "DIMCLRE" "ByLayer"); Extension line colour
    (setvar "DIMEXE" 0.125); Extension line extension
    (setvar "DIMEXO" 0.040); Extension line offset
    (setvar "DIMFRAC" 1); Fraction format
    (setvar "DIMLFAC" scale); Length scale
    (setvar "DIMLUNIT" 4); Length unit
    (setvar "DIMTIH" "off"); Text inside alignment
    (setvar "DIMGAP" 0.000); Text offset
    (setvar "DIMTOH" "off"); Text outside alignment
    (setvar "DIMTAD" 1); Text vertical position
    (setvar "DIMTXT" 0.125); Text height
    (setvar "DIMTXSTY" "Dimension"); Text style
    (setvar "DIMTZIN" 12); Tolerance zero suppression
    (setvar "DIMZIN" 12); Zero suppression
    
    (vla-copyfrom (strcat "Linear-" (rtos scale 2 2)) (strcat "Linear-" (rtos scale 2 2))); copy the new dimstyle over itself to keep the changes
    
    ;Create Diametric dimstyles
    (vla-copyfrom (strcat "Diametric-" (rtos scale 2 2)) (strcat "Linear-" (rtos scale 2 2)));
    (vla-put-activedimstyle doc (strcat "Linear-" (rtos scale 2 2))); Make the new dimstyle the active style
    
    ;Modify the new Diametric dimstyle
    (setvar "DIMTIH" "on"); Text inside alignment
    (setvar "DIMTOH" "on"); Text outisde alignment
    (setvar "DIMTAD" 0); Text vertical position
      
    (vla-copyfrom (strcat "Diametric-" (rtos scale 2 2)) (strcat "Diametric-" (rtos scale 2 2))); copy the new dimstyle over itself to keep the changes
  ); end foreach
); end Create_dimstyles

 

Link to comment
Share on other sites

9 hours ago, KGehrels said:

However, my boss is breathing down my neck so I need to get the code finished and am hoping that someone here will help.

 

is this in your assigned area of work? or did you say ill give it a shot?

 

"For some reason I can't get vla-put-activedimstyle to accept "Standard" as an input."

 

What happens when you only have one dimstyle?

  • it doesn't pass this if statment (if (> stylecount 1)
  • so scalelist is still a blank list
  • (foreach scale scalelist  AKA (foreach scale "empty list" AKA (foreach 0 times

  • skips all code to generate dimstyle

"So I'm trying to use vla-copyfrom right away to create the linear dimstyle then use vla-put-activedimstyle to make the new dimstyle the active style."

  • (vl-cmdf "-Dimstyle" "_S" "Standard" "Y")

 

Rather then recreate the wheel use Lee Mac's Steal lisp (look at examples you can import just dim styles)

so create a drawing template with all the styles already made and then pull from that.

 

(defun c:Create_dimstyles (/ Drawing styleset scalelist stylescale)
  (vl-load-com)
  (vla-startundomark (setq Drawing (vla-get-activedocument (vlax-get-acad-object)))) ; sets an undo to go back 
  ;purge maybe get ride of unused dimstyles?
  (setq styleset (vla-get-DimStyles Drawing)); Gets all dimstyles in the active document
  (setq scalelist '()); Creates an empty list
  (vlax-for style styleset; Finds the scale of each dimstyle and adds it to the beginning of scalelist
    (vla-put-activedimstyle doc style); Makes the active dimstyle
    (setq stylescale (GetVar 'dimlfac)); Gets the scale of the active dimstyle
    (if (not (member stylescale scalelist)) ;just test for duplicates as you create the list
      (setq scalelist (cons stylescale scalelist)); Adds the scale to scalelist
    )
  ); End vlax for
  ;prints are for error checking
  (princ (strcat "# of styles: " (itoa (vla-get-count styleset))))
  ;(print) ;not needed
  (princ "\nList of scales: ") ;"\n" = new line in command prompt
  (foreach scale scalelist
    (princ (strcat (rtos scale 2 2) ", "))
  ); end foreach
  ;prints are for error checking
  (foreach scale scalelist
    (Steal "C:\\My Folder\\MyDrawing.dwg" (list ("Dimension Styles" (strcat "Linear-" (rtos scale 2 2)) (strcat "Diametric-" (rtos scale 2 2)))))
  ); end foreach
  (vla-endundomark Drawing)
  (gc)
  (vla-Regen Drawing acAllViewports)
); end Create_dimstyles

 

Bonus points use mapcar with 'setvar to set a bunch of variables with only two lines of code.

(setq vars '(DIMASZ DIMCLRD DIMCLRE DIMEXE DIMEXO DIMFRAC DIMLFAC DIMLUNIT DIMTIH DIMGAP DIMTOH DIMTAD DIMTXT DIMTXSTY DIMTZIN DIMZIN))  ;list of variables
(mapcar 'setvar vars (list (0.130 "ByLayer" "ByLayer" 0.125 0.040 1 scale 4 "off" 0.000 "off" 1 0.125 "Dimension" 12 12))) ;set new values

 

Edited by mhupp
Link to comment
Share on other sites

The if statement is easily fixed with a >= instead of =.

As nice as the steal code is I'd like to keep everything in one package because, due to the way my company works, it's going to be passed from project to project and keeping the number of files to move as low as possible will reduce the number of errors due to people not grabbing all things.  This code is specific to one project type, a big one so it's worth it, so it won't be one that will get a template.  Hence trying to make a dimstyle through code.

 

There must be a way to do what I'm asking without having to copy and paste a dimstyle from somewhere else.

Link to comment
Share on other sites

Minor quibble, it's hard to read this code when a comment starts at the end of a statement. It's like the semicolon is the end of the command, which in some languages (like Java, C++, and SQL) it is. Also the expression (strcat "Linear-" (rtos scale 2 2)) shows up six times, why not evaluate it once, assign it to a temporary variable, and use that instead?

 

This seems to be the proper way to use vla-put-dimstyle:

  (setq newStyle (vla-item (vla-get-dimstyles doc) "aStyle"))
  (vla-put-dimstyle doc newStyle)

because why should it be simple?

 

That should get you back on track, but if not, check back with us.

Link to comment
Share on other sites

You could start from scratch.

 

This rather curiously named LISP was in my library "doesntworkentmakedimstyle"

 

I have commented out the parts that were stopping it from working. Maybe I should rename this "thisdoesworknowbutneedssomethinkingDimStyle"

 

I think this is the complete list to entmake a dimstyle - not everything in this list is necessary, and it created a dimstyle "Dim_Name" just then for me.

 

(defun c:doesntworkentmakedimstyle ( / )
(entmakex (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 "");(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- 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
  (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
  )) ; end list, end entmakex
  (princ)
)

 

 

and below is 'Jeff' which I use to quickly set a dim style - but for interest here are the descriptions which should match the above... though not in the same order of course, that would make life to easy.

 

;;Create Dimension Style
(defun tablesearch ( s / d r) ;;List Dimstyles
  (while (setq d (tblnext s (null d)))
    (setq r (cons (cdr (assoc 2 d)) r))
  )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;https://stackoverflow.com/questions/47835301/use-autolisp-to-generate-new-dimension-style
(defun c:SetDimStyle ( / )(jeff)) ;;Wrapper to change dimension style
(defun c:jeff ( / DimStyleName DSN FontStyleName FSN FontHeight TxtCol LinCol Col TxtPrecision TxtPrec) ;;change dimension style

;;Dimension Style
  (princ "\nEnter Dimension style Name ")(princ (tableSearch "dimstyle"))
  (setq DimStyleName (getvar "dimstyle"))
  (setq DSN (getstring (strcat ": (" DimStyleName "): ") t))
  (if (or (= DSN nil)(= DSN ""))
    (setq DimStyleName DimStyleName)
    (setq DimStyleName DSN)
  ) 
  (princ DimStyleName)

;;Font Style
  (princ  "\nEnter Font style Name ")(princ (tableSearch "style"))
;;  (setq FontStyleName (nth 0 (tableSearch "style")))
  (setq FontStyleName (getvar "textstyle"))
  (setq FSN (getstring (strcat " (" FontStyleName "): ") t))
  (if (or (= FSN nil)(= FSN ""))
    (setq FontStyleName FontStyleName)
    (setq FontStyleName FSN)
  )
  (princ FontStyleName)

;;Font Height
  (setq FontHeight 2.5) ;; How to get this from dimstyle selected above
  (setq FontHght (getreal (strcat "\nEnter Font Heght [" (rtos FontHeight)"]: ")))
  (if (or (= FontHght nil)(= FontHght ""))
    (setq FontHeight FontHeight)
    (setq FontHeight FontHght)
  )
  (princ FontHeight)

;;Colours
  (setq TxtCol 0) ;Text. 0: By Layer, 256: ByBlock
  (setq Col (getint (strcat "\nEnter Text Colour Code (0: ByLayer, 256: ByBock) [" (rtos TxtCol)"]: ")))
  (if (or (= Col nil)(= Col ""))
    (setq TxtCol TxtCol)
    (setq TxtCol Col)
  )
  (princ TxtCol)
  (setq LinCol 0) ;Lines. 0: By Layer, 256: ByBlock
  (setq Col (getint (strcat "\nEnter Lines Colour Code (0: ByLayer, 256: ByBock) [" (rtos LinCol)"]: ")))
  (if (or (= Col nil)(= Col ""))
    (setq LinCol LinCol)
    (setq LinCol Col)
  )
  (princ LinCol)

;;Precision
  (setq TxtPrecision 4) ; number of decimal places  ;; How to get this from dimstyle selected above
  (setq TxtPrec (getint (strcat "\nEnter Decimal Places) [" (rtos TxtPrecision) "]: ")))
  (if (or (= TxtPrec nil)(= TxtPrec ""))
    (setq TxtPrecision TxtPrecision)
    (setq TxtPrecision TxtPrec)
  )
  (princ TxtPrecision)(princ " DP")

  (setq DimensionScale (/ FontHeight 2.5))
  (jeff1 DimStyleName FontStyleName FontHeight TxtCol LinCol TxtPrecision DimensionScale)
  (princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun jeff1 ( DimStyleName FontName FontHeight TxtCol LinCol TxtPrecision DimensionScale / )
;;Sub Routines
  (defun mytextstyle ( myfont / mytextstyle fontcount fontlist) ;;check textstyle is loaded
  ;;Font Style Lists
  ;;Fontname Height WidthFactor ObliqueAngle Backwards UpsideDown
    (setq fontstyles (list
      (list "Standard" "Arial" "0.0000" "1.0000" "0" "No" "No")
      (list "romans" "romans.shx" "0.0000" "1.0000" "0" "No" "No")
      (list "MMArial" "Arial" "0.0000" "1.0000" "0" "No" "No")
      (list "MM_Arial" "Arial" "0.0000" "1.0000" "0" "No" "No")
    ));end fontstyles list

   (if (member myfont (tableSearch "style"))
    (princ "Font Is Loaded")
    (progn ; Font isn't loaded
      (setq fontcount 0)
      (while (< fontcount (length fontstyles))
        (if (= (strcase (nth 0 (nth fontcount fontstyles))) (strcase myfont))
          (progn ;font style is loaded
            (setq fontlist fontcount) ;;font style exists
          ) ; end progn
        ) ;end if
        (setq fontcount (+ 1 fontcount))
      )
  
      (if (= fontlist nil)
        (progn ;;if font is not defined above or loaded
          (alert "Font style needs loading. Please edit it")
          (command "Style" myfont "romans.shx" "0.0000" "1.0000" "0" "No" "No" "No")
          (initdia)
          (command "style")
        ) ;end progn
        (progn
          (command "style" (nth 0 (nth fontlist fontstyles)) (nth 1 (nth fontlist fontstyles))
                           (nth 2 (nth fontlist fontstyles)) (nth 3 (nth fontlist fontstyles))
                           (nth 4 (nth fontlist fontstyles)) (nth 5 (nth fontlist fontstyles))
                           (nth 6 (nth fontlist fontstyles)) (nth 7 (nth fontlist fontstyles))
          ) ;end command
        ) ;end progn
      ) ;end if
    ) ;end progn
    );end if
    (setq mystyle myfont) ;;text font style.. if anything else check if style is loaded into drawing here
    mystyle
  )
;;End Sub Routines

  (mytextstyle FontName) ;; Check Font exists else make it

;;Full list of dimension variables.
;;Change all or none as required, save and existing style to update
;;NOTE: BYBLOCK and other texts to be numbers?
;;https://help.autodesk.com/view/ACDLTM/2016/ENU/?guid=GUID-30F44A49-4250-42D1-AEF2-5E2914ADB02B
;;         List     value    ;; Default       ;;Description
 (setvar "DIMADEC"  TxtPrecision)  ;; 0       ;;Angular Dimension Decimal Places
;  (setvar "DIMALT"    0)    ;; 0              ;;Control of alternative units 0 - Off 1 - On
  (setvar "DIMALTD"   TxtPrecision)    ;; 2 / 3          ;;Alternative Units Decimal Places
;  (setvar "DIMALTF" 0.0394) ;; 25.4 / 0.0394  ;;Alternative Units Scale Factor
;;(setvar "DIMALTMZF")      ;;                ;;Alternate sub-zero factor for metric dimensions - Unknown variable
;;(setvar "DIMALTMZS")      ;;                ;;Alternate sub-zero suffix for metric dimensions - Unknown variable
;  (setvar "DIMALTRND" 0.00) ;; 0.00           ;;Alternate units rounding value
;  (setvar "DIMALTTD"  3)    ;; 2 / 3          ;;Alternative Units Tolerance Decimal Places
;  (setvar "DIMALTTZ"  0)    ;; 0              ;;Alternate tolerance zero suppression
;  (setvar "DIMALTU"   2)    ;; 2              ;;Alternative Units Units
;  (setvar "DIMALTZ"   0)    ;; 0              ;;Alternate unit zero suppression
;  (setvar "DIMAPOST" "")    ;; ""             ;;Prefix and suffix for alternate text
;  (setvar "DIMARCSYM" 0)    ;; 0              ;;Arc Length Dimension Arc Symbol
  (setvar "DIMASZ" FontHeight) ;; 0.18 / 2.5  ;;Dimension Line and Leader Line Arrow Heads size
;  (setvar "DIMATFIT"  3)    ;; 3              ;;Arrow and text fit if distance is too narrow for both
;  (setvar "DIMAUNIT"  0)    ;; 0              ;;Angular unit format
;  (setvar "DIMAZIN"   0)    ;; 0              ;;Angular Dimension Depresses leading zeros
;  (setvar "DIMBLK"  ".")    ;; "."            ;;Arrow block name "." for closed flled else as properties
;  (setvar "DIMBLK1" ".")    ;; "."            ;;First arrow block name "." for closed flled else as properties
;  (setvar "DIMBLK2" ".")    ;; "."            ;;Second arrow block name "." for closed flled else as properties
  (setvar "DIMCEN" FontHeight) ;; 0.09 / 2.5  ;;Drawing centre mark for radius or diameter dimensions
  (setvar "DIMCLRD" LinCol) ;; 0              ;;Colours - Lines, ArrowHeads, Dimension Lines 0: ByLayer, 256 ByBlock
  (setvar "DIMCLRE" LinCol) ;; 0              ;;Colours - Extension Lines, Centre Marks Colours 0: ByLayer, 256 ByBlock
  (setvar "DIMCLRT" TxtCol) ;; 0              ;;Colours - Dimension Text Colour 0: ByLayer, 256 ByBlock
  (setvar "DIMDEC"  TxtPrecision)  ;; 0       ;;Dimension Decimal Places
;  (setvar "DIMDLE"    0)    ;; 0.0000         ;;Dimension Line extension with oblique strokes instead of arrows
;  (setvar "DIMDLI"    4)    ;; 3.75           ;;Dimension Baseline Dimension Spacing
  (setvar "DIMDSEP" ".")    ;; .              ;;Decimal separator
  (setvar "DIMEXE" (/ Fontheight 2)) ;; 0.18 / 1.25    ;;Extension Line Extension distance
  (setvar "DIMEXO" (/ Fontheight 4)) ;; 0.0625 / 0.625 ;;Extension Line Offset
;  (setvar "DIMFRAC"   0)    ;; 0              ;;Dimension Fraction Format
;  (setvar "DIMFXL" 1.00)    ;; 1              ;;Fixed Extension Line
;  (setvar "DIMFXLON"  0)    ;; 0              ;;Enable Fixed Extension Line 0 - Off 1 - On
  (setvar "DIMGAP" (/ FontHeight 4)) ;; 0.09 / 0.625   ;;Dimension gap between text and arrow 
  (setvar "DIMJOGANG" (* pi (/ 45 180.0))) ;; ;;Radius dimension jog angle.. radians?
;  (setvar "DIMJUST"   0)    ;; 0              ;;Justification of text on dimension line
  (setvar "DIMLDRBLK" ".")  ;; "."            ;;Leader block name "." for closed flled else as properties
;  (setvar "DIMLFAC" 1.00)   ;; 1              ;;Linear unit scale factor
;  (setvar "DIMLIM"    0)    ;; 0              ;;Generate dimension limits 0 - Off 1 - On
  (setvar "DIMLTEX1" "BYBLOCK")    ;;  "."    ;;Linetype extension line 1
  (setvar "DIMLTEX2" "BYBLOCK")    ;;  "."    ;;Linetype extension line 2
  (setvar "DIMLTYPE" "BYBLOCK")    ;;  "."    ;;Dimension linetype
;  (setvar "DIMLUNIT"  2)    ;; 2              ;;Dimension Units (except angular) - number type
;  (setvar "DIMLWD"   -2)    ;; -2             ;;Dimension Line Lineweights
;  (setvar "DIMLWE"   -2)    ;; -2             ;;Extension Line Line Weight
;;(setvar "DIMMZF")         ;;                ;;Sub-zero factor for metric dimensions - Unknown variable
;;(setvar "DIMMZS")         ;;                ;;Sub-zero suffix for metric dimensions - Unknown variable
;  (setvar "DIMPOST" "")     ;; ""             ;;Prefix and suffix for dimension text
;  (setvar "DIMRND"   0)     ;; 0              ;;Dimension Round distance to nearest n
;  (setvar "DIMSAH"   0)     ;; 0              ;;Separate arrow blocks 0 - Off 1 - On
;  (setvar "DIMSCALE" 1)     ;; 1              ;;Dimension Scale Factor
;  (setvar "DIMSD1"   0)     ;; 0              ;;Suppress the first dimension line 0 - Off 1 - On
;  (setvar "DIMSD2"   0)     ;; 0              ;;Suppress the second dimension line 0 - Off 1 - On
;  (setvar "DIMSE1"   0)     ;; 0              ;;Suppress the first extension line 0 - Off 1 - On
;  (setvar "DIMSE2"   0)     ;; 0              ;;Suppress the second extension line 0 - Off 1 - On
;  (setvar "DIMSOXD"  0)     ;; 0              ;;Suppress outside dimension lines
;  (setvar "DIMTAD"   0)     ;; 0              ;;Dimension Text Vertical distance
;  (setvar "DIMTDEC"  4)     ;; 4              ;;Tolerance decimal places
;  (setvar "DIMTFAC"  1)     ;; 1              ;;Dimension text scale factor of fractions relative to text height
;  (setvar "DIMTFILL" 0)     ;; 0              ;;Text background enabled
;  (setvar "DIMTFILLCLR" 0)  ;; 0              ;;Text background color 0: ByLayer, 256 ByBlock
;  (setvar "DIMTIH"   0)     ;; 0              ;;Text inside extensions is horizontal 0 - Off 1 - On
;  (setvar "DIMTIX"   0)     ;; 0              ;;Place text inside extensions 0 - Off 1 - On
;  (setvar "DIMTM"    0)     ;; 0              ;;Dimension Minus tolerance distance when used with dimtol, or dimlim
;  (setvar "DIMTMOVE" 0)     ;; 0              ;;Text movement
;  (setvar "DIMTOFL"  0)     ;; 0              ;;Force line inside extension lines 0 - Off 1 - On
;  (setvar "DIMTOH"   1)     ;; 1              ;;Text outside horizontal 0 - Off 1 - On
;  (setvar "DIMTOL"   0)     ;; 0              ;;Tolerance dimensioning 0 - Off 1 - On
;  (setvar "DIMTOLJ"  1)     ;; 0              ;;Tolerance vertical justification
;  (setvar "DIMTP"    0)     ;; 0              ;;Dimension Plus tolerance distance when used with dimtol, or dimlim
;  (setvar "DIMTSZ" 0.00)    ;; 0              ;;Tick size
;  (setvar "DIMTVP" 0.00)    ;; 0              ;;Text vertical position
  (setvar "DIMTXSTY" FontName)     ;; Font    ;;Text style
  (setvar "DIMTXT" FontHeight)     ;; 0.18 / 2.5   ;;Dimension text Height
;;(setvar "DIMTXTDIRECTIONOff" 0)  ;;         ;;Dimension text direction 1 or 0 - NOT SURE IF THIS WORKS
;  (setvar "DIMTZIN"  8)     ;; 8              ;;Suppresses leading zeros in tolerance values
;  (setvar "DIMUPT"   0)     ;; 0              ;;User positioned text 0 - Off 1 - On
;  (setvar "DIMZIN"   8)     ;; 8              ;;Suppresses leading zeroes

;;Set Dimstyle named above to this list
  (setq dimstylelist (tableSearch "dimstyle"))
  (if (= (member DimStyleName dimstylelist) nil)
    (command "dimstyle" "s" DimStyleName)
    (command "dimstyle" "s" DimStyleName "Y")
  )
    (princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

 

  • Funny 1
Link to comment
Share on other sites

4 hours ago, KGehrels said:

The if statement is easily fixed with a >= instead of =.

 

Yes, but their is always going to be at least one dimstyle so why have the if statement if its always going to be true.

 

--Edit

Steven you could make it so you have declared variables to call to make the dimstyles

 

(defun doesntworkentmakedimstyle (Name Scale /)
  ...
  (cons 2 name)   ;Dim style name
  (cons 144 scale) ;Dim style scale
  ...
  

called with
(doesntworkentmakedimstyle (strcat "Linear-" (rtos scale 2 2)) scale)
;scale might have to be set as a double so 1.0 insted of 1

 

Edited by mhupp
  • Like 1
Link to comment
Share on other sites

Thanks CyberAngel.  It took me a bit to get things sorted but those two lines of yours were the jumping point I needed. 

Noted about the comments.  I'll switch for my next bit of code.

 

Incidentally,  by "vla-put-dimstyle doc newStyle"  did you mean "vla-put-ACTIVEdimstyle doc newStyle"?  I ask because I could get the code to work without the change and I'm hoping that I'm not missing something.

 

Now I just need to figure out how to set the line colours to be "bylayer".  (setvar "DIMCLRD" "Bylayer") doesn't work.  0 is "Byblock" and any number after that is a colour.

 

Thank you again.  This is a big leap forward.

 

Here's the code for anyone that might need it:

(defun c:Create_dimstyles ( / acadObj doc styleset stylecount scalelist stylecount style stylescale scale unique-scalelist currentDimStyle lstylename dstylename standardstyle)
  (vl-load-com)
  (setq acadObj (vlax-get-acad-object))
  (setq doc (vla-get-activedocument acadObj))
  
  (setq styleset (vla-get-DimStyles doc)); Gets all dimstyles in the active document
  (setq stylecount (vla-get-count styleset))
  (setq scalelist '()); Creates an empty list
    
  (if (>= stylecount 1); Checks if there is more than one dimstyle
    (progn
      (vlax-for style styleset; Finds the scale of each dimstyle and adds it to the beginning of scalelist
        (vla-put-activedimstyle doc style); Makes the active dimstyle
        (setq stylescale (GetVar "DimLFac")); Gets the scale of the active dimstyle
        (setq scalelist (cons stylescale scalelist)); Adds the scale to scalelist
      ); End vlax for
      (setq scalelist (vl-sort scalelist '<)); Sorts the scales from smallest to largest
      (setq unique-scalelist '())
      (foreach scale scalelist; removes duplicates
        (if (not (member scale unique-scalelist))
          (setq unique-scalelist (cons scale unique-scalelist))
        ); end if
      ); foreach
      (setq scalelist (reverse unique-scalelist)); rea
    ); end progn
  ); End if
  
  ;prints are for error checking
  (princ (strcat "# of styles: " (itoa stylecount)))
  (print)
  (princ "List of scales: ")
  (foreach scale scalelist
    (princ(strcat (rtos scale 2 2) ", "))
  ); end foreach

  ;prints are for error checking
  
  (foreach scale scalelist
    ;Create Linear dimstyles
    (setq lstylename (strcat "Linear-" (rtos scale 2 0))); Define the style name
    (vla-add (vla-get-dimstyles doc) lstylename); Create a new dimstyle with the above name
    (setq lstyle (vla-item (vla-get-dimstyles doc) lstylename)); Define a variable for the new style
    (vla-put-activedimstyle doc lstyle); Sets the new style as the current dimstyle
    
    ;Modify the new linear dimstyle
    (setvar "DIMASZ" 0.130) ; Arrow size
    ;(setvar "DIMCLRD" "ByLayer"); Dimension line colour
    ;(setvar "DIMCLRE" "ByLayer"); Extension line colour
    (setvar "DIMEXE" 0.125); Extension line extension
    (setvar "DIMEXO" 0.040); Extension line offset
    (setvar "DIMFRAC" 1); Fraction format
    (setvar "DIMLFAC" scale); Length scale
    (setvar "DIMLUNIT" 4); Length unit
    (setvar "DIMTIH" 0); Text inside alignment
    (setvar "DIMGAP" 0.000); Text offset
    (setvar "DIMTOH" 0); Text outside alignment
    (setvar "DIMTAD" 1); Text vertical position
    (setvar "DIMTXT" 0.125); Text height
    (setvar "DIMTXSTY" "Dimension"); Text style
    (setvar "DIMTZIN" 12); Tolerance zero suppression
    (setvar "DIMZIN" 12); Zero suppression

    (vla-copyfrom lstyle doc)

    ;Create Diametric dimstyles
    (setq dstylename (strcat "Diametric-" (rtos scale 2 0))); Define the style name
    (vla-add (vla-get-dimstyles doc) dstylename); Create a new dimstyle with the above name
    (setq dstyle (vla-item (vla-get-dimstyles doc) dstylename)); Define a variable for the new style
    (vla-put-activedimstyle doc dstyle); Sets the new style as the current dimstyle
    
    ;Modify the new diametric dimstyle
    (setvar "DIMASZ" 0.130) ; Arrow size
    (setvar "DIMTIH" 1); Text inside alignment
    (setvar "DIMTOH" 1); Text outisde alignment
    (setvar "DIMTAD" 0); Text vertical position
      
    (vla-copyfrom dstyle doc); copy the new dimstyle over itself to keep the changes
  ); end foreach
  
  (setq standardstyle (vla-item (vla-get-dimstyles doc) "Standard")); Define a variable for the new style
  (vla-put-activedimstyle doc standardstyle); Sets the standard dim style as the active dimstyle
  (princ)
); end Create_dimstyles

 

Link to comment
Share on other sites

1 hour ago, mhupp said:

 

Steven you could make it so you have declared variables to call to make the dimstyles

 

(defun doesntworkentmakedimstyle (Name Scale /)
  ...
  (cons 2 name)   ;Dim style name
  (cons 144 scale) ;Dim style scale
  ...
  

called with
(doesntworkentmakedimstyle (strcat "Linear-" (rtos scale 2 2)) scale)
;scale might have to be set as a double so 1.0 insted of 1

 

 

That's what I was thinking, make it into a little LISP function and when you call it send the info it needs to create the dim-style as required. 

Link to comment
Share on other sites

1 minute ago, KGehrels said:

Found it.

256 = ByLayer

 

I'd have to check, some things are -1 for by block if you need that as well - need to check though

Link to comment
Share on other sites

2 hours ago, mhupp said:

Yes, but their is always going to be at least one dimstyle so why have the if statement if its always going to be true.

Good point.  I modified it to be >= 2 so that it would go if there is more than the standard style.  The other option that jumps to mind is make the condition to look for at least one style that is not labeled "standard".

Link to comment
Share on other sites

37 minutes ago, KGehrels said:

Incidentally,  by "vla-put-dimstyle doc newStyle"  did you mean "vla-put-ACTIVEdimstyle doc newStyle"?  I ask because I could get the code to work without the change and I'm hoping that I'm not missing something.

 

As I understand it, vla-put-dimstyle adds a style to the dictionary, while vla-put-activedimstyle only makes it current... which shouldn't work if it's not in the dictionary to begin with.

 

But if AutoCAD uses it that way, it's the right command.

 

I checked, and activedimstyle does set the current style, as you'd expect. If I get some time, I'll check the other one.

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...