Author Topic: Import Dimension Style  (Read 868 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Import Dimension Style
« on: September 14, 2022, 09:31:07 AM »

Good morning, Having a little issue with the following code for inserting settings to dimension style. I believe the code is CAB's

Code: [Select]
(defun c:IDIM (/ acdoc dsobj obj)
(vl-load-com)
  (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
  (setq dsobj (vla-get-dimstyles acdoc))
  (vlax-for obj dsobj
    (vla-put-activedimstyle acdoc (vla-item dsobj (vla-get-name obj))) ;set dimstyle current
    (vlax-invoke acdoc 'setvariable "DIMADEC" 0)
    (vlax-invoke acdoc 'setvariable "DIMALT" 0)
    (vlax-invoke acdoc 'setvariable "DIMALTD" 2)
    (vlax-invoke acdoc 'setvariable "DIMALTF" 25.4000)
    (vlax-invoke acdoc 'setvariable "DIMALTRND" 0.0000)
    (vlax-invoke acdoc 'setvariable "DIMALTTD" 2)
    (vlax-invoke acdoc 'setvariable "DIMALTTZ" 0)
    (vlax-invoke acdoc 'setvariable "DIMALTU" 2)
    (vlax-invoke acdoc 'setvariable "DIMALTZ" 0)
    (vlax-invoke acdoc 'setvariable "DIMARCSYM" 0)
    (vlax-invoke acdoc 'setvariable "DIMASSOC" 2)
    (vlax-invoke acdoc 'setvariable "DIMASZ" 0.1800)
    (vlax-invoke acdoc 'setvariable "DIMATFIT" 3)
    (vlax-invoke acdoc 'setvariable "DIMAUNIT" 0)
    (vlax-invoke acdoc 'setvariable "DIMAZIN" 0)
    (vlax-invoke acdoc 'setvariable "DIMCEN" 0.0900)
    (vlax-invoke acdoc 'setvariable "DIMCLRD" 0)
    (vlax-invoke acdoc 'setvariable "DIMCLRE" 0)
    (vlax-invoke acdoc 'setvariable "DIMCLRT" 0)
    (vlax-invoke acdoc 'setvariable "DIMCONSTRAINTICON" 3)
    (vlax-invoke acdoc 'setvariable "DIMCONTINUEMODE" 1)
    (vlax-invoke acdoc 'setvariable "DIMDEC" 2)
    (vlax-invoke acdoc 'setvariable "DIMDLE" 0.0000)
    (vlax-invoke acdoc 'setvariable "DIMDLI" 0.3800)
    (vlax-invoke acdoc 'setvariable "DIMEXE" 0.1800)
    (vlax-invoke acdoc 'setvariable "DIMEXO" 0.0625)
    (vlax-invoke acdoc 'setvariable "DIMFRAC" 0)
    (vlax-invoke acdoc 'setvariable "DIMFXL" 1.0000)
    (vlax-invoke acdoc 'setvariable "DIMFXLON" 0)
    (vlax-invoke acdoc 'setvariable "DIMGAP" 1.0000)
    ;(vlax-invoke acdoc 'setvariable "DIMJOGANG" 0.7854)
    (vlax-invoke acdoc 'setvariable "DIMJUST" 0)
    (vlax-invoke acdoc 'setvariable "DIMLFAC" 1.0000)
    (vlax-invoke acdoc 'setvariable "DIMLIM" 0)
    (vlax-invoke acdoc 'setvariable "DIMLUNIT" 2)
    (vlax-invoke acdoc 'setvariable "DIMLWD" -2)
    (vlax-invoke acdoc 'setvariable "DIMLWE" -2)
    (vlax-invoke acdoc 'setvariable "DIMPICKBOX" 5)
    (vlax-invoke acdoc 'setvariable "DIMRND" 0.0000)
    (vlax-invoke acdoc 'setvariable "DIMSAH" 0)
    (vlax-invoke acdoc 'setvariable "DIMSCALE" 1.0000)
    (vlax-invoke acdoc 'setvariable "DIMSD1" 1)
    (vlax-invoke acdoc 'setvariable "DIMSD2" 1)
    (vlax-invoke acdoc 'setvariable "DIMSE1" 1)
    (vlax-invoke acdoc 'setvariable "DIMSE2" 1)
    (vlax-invoke acdoc 'setvariable "DIMSOXD" 0)
    (vlax-invoke acdoc 'setvariable "DIMTAD" 1)
    (vlax-invoke acdoc 'setvariable "DIMTDEC" 2)
    (vlax-invoke acdoc 'setvariable "DIMTFAC" 1.0000)
    (vlax-invoke acdoc 'setvariable "DIMTFILL" 0)
    (vlax-invoke acdoc 'setvariable "DIMTFILLCLR" 0)
    (vlax-invoke acdoc 'setvariable "DIMTIH" 0)
    (vlax-invoke acdoc 'setvariable "DIMTIX" 0)
    (vlax-invoke acdoc 'setvariable "DIMTM" 0.0000)
    (vlax-invoke acdoc 'setvariable "DIMTMOVE" 0)
    (vlax-invoke acdoc 'setvariable "DIMTOFL" 0)
    (vlax-invoke acdoc 'setvariable "DIMTOH" 0)
    (vlax-invoke acdoc 'setvariable "DIMTOL" 0)
    (vlax-invoke acdoc 'setvariable "DIMTOLJ" 1)
    (vlax-invoke acdoc 'setvariable "DIMTP" 0.0000)
    (vlax-invoke acdoc 'setvariable "DIMTSZ" 0.0000)
    (vlax-invoke acdoc 'setvariable "DIMTVP" 0.0000)
    (vlax-invoke acdoc 'setvariable "DIMTXSTY" Standard)
    (vlax-invoke acdoc 'setvariable "DIMTXT" 3.5000)
    (vlax-invoke acdoc 'setvariable "DIMTXTDIRECTION" 0)
    (vlax-invoke acdoc 'setvariable "DIMTXTRULER" 1)
    (vlax-invoke acdoc 'setvariable "DIMTZIN" 0)
    (vlax-invoke acdoc 'setvariable "DIMUPT" 0)
    (vlax-invoke acdoc 'setvariable "DIMZIN" 0)
    (vla-copyfrom obj acdoc) ; update the Dim Style
  )
  (princ)
)


It produces the following error in Autocad Civil 3D

Quote
; error: Autodesk Civil 3D 2023: Error setting system variable
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: Import Dimension Style
« Reply #1 on: September 14, 2022, 10:57:28 AM »
HINT, if you have the dimension style created then create a block with that dimension style in a separate DWG and locate it in any of AutoCAD search paths.
So now you can import the block with the insert command very easily.

JohnK

  • Administrator
  • Seagull
  • Posts: 10604
Re: Import Dimension Style
« Reply #2 on: September 14, 2022, 11:06:11 AM »
The error is because you are trying to set an error Civil3D doesn't like. I'm sure if you used VSCode/vlide you can find the pesky variable.

FWITW: I still use this ancient method (almost the same principal). I have not found a reason to update it, honestly.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:CreateDimstyle ()
  2.  (command "-style" "Annotative-Default" "Arial.ttf" "Annotative" "yes" "no" "0.09375" "1.0" "0" "no" "no")
  3.  (mapcar        'eval
  4.   '((setvar "DIMADEC" 0)          (setvar "DIMALT" 0)             (setvar "DIMALTD" 2)
  5.     (setvar "DIMALTF" 25.4)       (setvar "DIMALTRND" 0.0)        (setvar "DIMALTTD" 2)
  6.     (setvar "DIMALTTZ" 0)         (setvar "DIMALTU" 2)            (setvar "DIMALTZ" 0)
  7.     (setvar "DIMAPOST" "")        (setvar "DIMASZ" 0.125)         (setvar "DIMATFIT" 3)
  8.     (setvar "DIMAUNIT" 0)         (setvar "DIMAZIN" 0)            (setvar "DIMBLK1" "")
  9.     (setvar "DIMBLK2" "")         (setvar "DIMCEN" 0.09375)       (setvar "DIMCLRD" 256)
  10.     (setvar "DIMCLRE" 256)        (setvar "DIMCLRT" 256)          (setvar "DIMDEC" 1)
  11.     (setvar "DIMDLE" 0.0)         (setvar "DIMDLI" 0.125)         (setvar "DIMEXE" 0.0625)
  12.     (setvar "DIMEXO" 0.0625)      (setvar "DIMFRAC" 0)            (setvar "DIMGAP" 0.0625)
  13.     (setvar "DIMJUST" 0)          (setvar "DIMLFAC" 1.0)          (setvar "DIMLIM" 0)
  14.     (setvar "DIMLUNIT" 2)         (setvar "DIMLWD" -2)            (setvar "DIMLWE" -2)
  15.     (setvar "DIMPOST" "")         (setvar "DIMRND" 0.0)           (setvar "DIMSAH" 0)
  16.     (setvar "DIMSD1" 0)           (setvar "DIMSD2" 0)             (setvar "DIMSE1" 0)
  17.     (setvar "DIMSE2" 0)           (setvar "DIMSOXD" 0)            (setvar "DIMTAD" 1)
  18.     (setvar "DIMTDEC" 1)          (setvar "DIMTFAC" 1.0)          (setvar "DIMTIH" 1)
  19.     (setvar "DIMTIX" 0)           (setvar "DIMTM" 0.0)            (setvar "DIMTMOVE" 0)
  20.     (setvar "DIMTOFL" 0)          (setvar "DIMTOH" 1)             (setvar "DIMTOL" 0)
  21.     (setvar "DIMTOLJ" 1)          (setvar "DIMTP" 0.0)            (setvar "DIMTSZ" 0.0)
  22.     (setvar "DIMTXT" 0.03125)     (setvar "DIMTZIN" 0)            (setvar "DIMUPT" 0)
  23.     (setvar "DIMTVP" 0.0)         (setvar "DIMTXSTY" "Annotative-Default")
  24.     )
  25.   )
  26.   (command "-dimstyle" "AN" "yes" "Annotative-Default" "")
  27. )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Import Dimension Style
« Reply #3 on: September 14, 2022, 11:10:32 AM »

@Tharwat - Just a fantastic idea.

@JohnK - Thanks for the input.

Much appreciated guys.....

Thanks,

V-Man
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Lonnie

  • Newt
  • Posts: 169
Re: Import Dimension Style
« Reply #4 on: September 14, 2022, 04:28:04 PM »
Something along Tharwat's answer.
I did this not a week ago for layers.



Code - Auto/Visual Lisp: [Select]
  1. (defun SS_sslist ()
  2.  
  3.         ssl (if ss (sslength ss) 0)
  4.         cnt 0
  5.         ELst '()
  6. )
  7.  
  8. (repeat ssl
  9.         (setq
  10.                 ELst (cons (ssname ss cnt) ELst)
  11.                 cnt (1+ cnt)
  12.         )
  13. )
  14. ;(setq tear_into_this (reverse ELst))
  15.  
  16.     (command "change" ss "" "p" "layer" set-to-this-layer "")
  17.    (foreach temp_var ELst (if (or (= (cdr (assoc 0 (entget temp_var))) "TEXT")
  18.                                             (= (cdr (assoc 0 (entget temp_var))) "LEADER")
  19.                                             (= (cdr (assoc 0 (entget temp_var))) "MTEXT"))
  20. (COMMAND "CHANGE" temp_var "" "p" "layer" set-to-this-layer-for-txt ""))
  21.   )
  22.   (Princ "Moved to ") (prin1 (strcase set-to-this-layer)) (Prompt " or ") (prin1 (strcase set-to-this-layer-for-txt))
  23.   (setvar "cmdecho" 0)
  24. )
  25.  
  26. ---End This needs to be here---
  27.  
  28. ;;; 2022-09-01 Fire Control Layers
  29.  
  30.     (defun c:F-AUX0 ()
  31.   (setq ss (ssget))(command "undo" "begin")
  32.   (setq set-to-this-layer "F-AUX0")
  33.   (setq set-to-this-layer-for-txt "F-AUX0")
  34.          (if (= (tblsearch "layer" set-to-this-layer) nil) (command "-INSERT" "*//designdata/cadd/ACAD/DEFAULT/General/Symbols/firecontrollayers.DWG" "0,0" "1" ""))
  35. (setvar "clayer" set-to-this-layer)(SS_sslist)(command "undo" "end")
  36.   )


EDIT (John): Added code tags.
« Last Edit: September 15, 2022, 09:06:16 AM by JohnK »