Jump to content

Import Styles from a certain DWG LISP


Subidoooo

Recommended Posts

Hi guys i have a couple of text and dimension styles that i want users to be able to copy from a DWG in a certain path. i want to add this to my lisp so that its being done automatically, can you guys help

Link to comment
Share on other sites

Add your desired objects that you want to import to a new block then import them via insert command and the block name should be the entire path of the drawing that obtains the block.

Link to comment
Share on other sites

This will let you 'steal' from another drawing: http://www.lee-mac.com/steal.html though I have never looked at it to see if you can just set it to run and 'steal' when you open a drawing with no user interaction. It should be possible if you take the time to work it out.

 

A second way to do this rather than stealing is just to define the styles via a LISP, load that and run to set it all as required. If you want to control this from a central location you could save the LISP centrally, update as required. This is what I would do.

 

This will create a font style in the drawing for example. Repeat for each font style to create. I would also do an 'if' in case the font is in the drawing, your choice then to update the font or do nothing (remembering that changing a font might also affect how the drawing looks)

 

(defun c:CreateFontStyle ( / myfont )
  (setq myfont "FontName")
  (command "-Style" myfont "romans.shx" "0.0000" "1.0000" "0" "No" "No" "No")
  (setvar "textstyle" myfont)
  (princ)
)

 

Dimensions have a lot more variables than texts..... You could use this as the basis to set your own dimstyle and make it the current one. 'dimvariableslist' is a list of the dimension variables in the order of the list near the bottom of this - set as required. As it is this will create dimension "00000204F71894182" (No idea where this name came from)

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Based on the work done here
;;https://stackoverflow.com/questions/47835301/use-autolisp-to-generate-new-dimension-style

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:jefflist ( / DimStyleName DSN FontStyleName FSN DimensionScale dimvariableslist)

;;;;;;;;;;A List of all the dimension variables. Copy and paste from clipboard to here ;;;;;;;;;;;;;;
;;;;;;;;;Maybe consider adding a 'wrapper' LISP calling this one and passing to it your;;;;;;;;;;;;;;
;;;;;;;; DimName and dimvariableslist variables (below) one at a time for each dim style;;;;;;;;;;;;;

  (setq DimName "00000204F71894182")
  (setq dimvariableslist (list 0 0 2 25.4 0.0 2 0 2 0 "" 0 0.85 3 0 0 "" "" "" 0.09 1 1 1 4 0.0 0.38 "." 0.18 0.0625 2 1.0 0 0.09 0.785398 0 "" 1.0 0 "ByBlock" "ByBlock" "ByBlock" 5 -2 -2 "\"" 0.0 0 1.0 0 0 0 0 0 0 4 1.0 0 0 1 0 0.0 0 0 1 0 1 0.0 0.0 0.0 "Standard" 0.63 0 0 0))

;;;;;;;;;;End of dimension description ;;;;;;;;;;;;;;



;;Sub Routines
  (defun tablesearch ( s / d r) ;;List Dimstyles
    (while (setq d (tblnext s (null d)))
      (setq r (cons (cdr (assoc 2 d)) r))
    )
  )

  (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 "CoArial" "Arial" "0.0000" "1.0000" "0" "No" "No")
      (list "Company_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


;;Dimension Style
  (princ "Exsting DIM styles: ")(princ (tableSearch "dimstyle"))
  (setq DimStyleName (nth 0 (tableSearch "dimstyle")))
  (setq DSN DimName)
  (if (or (= dsn nil)(= DSN ""))
    (setq DimStyleName DimStyleName)
    (setq DimStyleName DSN)
  ) 

;;Font Style
  (princ  "Loaded Text Fonts: ")(princ (tableSearch "style"))
  (setq FontStyleName (nth 0 (tableSearch "style")))
  (setq FSN (nth 68 dimvariableslist) )
  (if (or (= dsn nil)(= DSN ""))
    (setq FontStyleName FontStyleName)
    (setq FontStyleName FSN)
  ) 
  (mytextstyle FontStyleName)

;;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
 (setvar "DIMADEC"    (nth  0 dimvariableslist));;Angular Dimension Decimal Places
  (setvar "DIMALT"    (nth  1 dimvariableslist));;Control of alternative units 0 - Off 1 - On
  (setvar "DIMALTD"   (nth  2 dimvariableslist));;Alternative Units Decimal Places
  (setvar "DIMALTF"   (nth  3 dimvariableslist));;Alternative Units Scale Factor
  (setvar "DIMALTRND" (nth  4 dimvariableslist));;Alternate units rounding value
  (setvar "DIMALTTD"  (nth  5 dimvariableslist));;Alternative Units Tolerance Decimal Places
  (setvar "DIMALTTZ"  (nth  6 dimvariableslist));;Alternate tolerance zero suppression
  (setvar "DIMALTU"   (nth  7 dimvariableslist));;Alternative Units Units
  (setvar "DIMALTZ"   (nth  8 dimvariableslist));;Alternate unit zero suppression
  (setvar "DIMAPOST"  (nth  9 dimvariableslist));;Prefix and suffix for alternate text
  (setvar "DIMARCSYM" (nth 10 dimvariableslist));;Arc Length Dimension Arc Symbol
  (setvar "DIMASZ"    (nth 11 dimvariableslist));;Dimension Line and Leader Line Arrow Heads size
  (setvar "DIMATFIT"  (nth 12 dimvariableslist));;Arrow and text fit if distance is too narrow for both
  (setvar "DIMAUNIT"  (nth 13 dimvariableslist));;Angular unit format
  (setvar "DIMAZIN"   (nth 14 dimvariableslist));;Angular Dimension Depresses leading zeros
  (setvar "DIMBLK"    (nth 15 dimvariableslist));;Arrow block name "." for closed flled else as properties
  (setvar "DIMBLK1"   (nth 16 dimvariableslist));;First arrow block name "." for closed flled else as properties
  (setvar "DIMBLK2"   (nth 17 dimvariableslist));;Second arrow block name "." for closed flled else as properties
  (setvar "DIMCEN"    (nth 18 dimvariableslist));;Drawing centre mark for radius or diameter dimensions
  (setvar "DIMCLRD"   (nth 19 dimvariableslist));;Colours - Lines, ArrowHeads, Dimension Lines 0: ByLayer, 256 ByBlock
  (setvar "DIMCLRE"   (nth 20 dimvariableslist));;Colours - Extension Lines, Centre Marks Colours 0: ByLayer, 256 ByBlock
  (setvar "DIMCLRT"   (nth 21 dimvariableslist));;Colours - Dimension Text Colour 0: ByLayer, 256 ByBlock
  (setvar "DIMDEC"    (nth 22 dimvariableslist));;Dimension Decimal Places
  (setvar "DIMDLE"    (nth 23 dimvariableslist));;Dimension Line extension with oblique strokes instead of arrows
  (setvar "DIMDLI"    (nth 24 dimvariableslist));;Dimension Baseline Dimension Spacing
  (setvar "DIMDSEP"   (nth 25 dimvariableslist));;Decimal separator
  (setvar "DIMEXE"    (nth 26 dimvariableslist));;Extension Line Extension distance
  (setvar "DIMEXO"    (nth 27 dimvariableslist));;Extension Line Offset
  (setvar "DIMFRAC"   (nth 28 dimvariableslist));;Dimension Fraction Format
  (setvar "DIMFXL"    (nth 29 dimvariableslist));;Fixed Extension Line
  (setvar "DIMFXLON"  (nth 30 dimvariableslist));;Enable Fixed Extension Line 0 - Off 1 - On
  (setvar "DIMGAP"    (nth 31 dimvariableslist));;Dimension gap between text and arrow 
  (setvar "DIMJOGANG" (nth 32 dimvariableslist));;Radius dimension jog angle.. radians?
  (setvar "DIMJUST"   (nth 33 dimvariableslist));;Justification of text on dimension line
  (setvar "DIMLDRBLK" (nth 34 dimvariableslist));;Leader block name "." for closed flled else as properties
  (setvar "DIMLFAC"   (nth 35 dimvariableslist));;Linear unit scale factor
  (setvar "DIMLIM"    (nth 36 dimvariableslist));;Generate dimension limits 0 - Off 1 - On
  (setvar "DIMLTEX1"  (nth 37 dimvariableslist));;Linetype extension line 1
  (setvar "DIMLTEX2"  (nth 38 dimvariableslist));;Linetype extension line 2
  (setvar "DIMLTYPE"  (nth 39 dimvariableslist));;Dimension linetype
  (setvar "DIMLUNIT"  (nth 40 dimvariableslist));;Dimension Units (except angular) - number type
  (setvar "DIMLWD"    (nth 41 dimvariableslist));;Dimension Line Lineweights
  (setvar "DIMLWE"    (nth 42 dimvariableslist));;Extension Line Line Weight
  (setvar "DIMPOST"   (nth 43 dimvariableslist));;Prefix and suffix for dimension text
  (setvar "DIMRND"    (nth 44 dimvariableslist));;Dimension Round distance to nearest n
  (setvar "DIMSAH"    (nth 45 dimvariableslist));;Separate arrow blocks 0 - Off 1 - On
  (setvar "DIMSCALE"  (nth 46 dimvariableslist));;Dimension Scale Factor
  (setvar "DIMSD1"    (nth 47 dimvariableslist));;Suppress the first dimension line 0 - Off 1 - On
  (setvar "DIMSD2"    (nth 48 dimvariableslist));;Suppress the second dimension line 0 - Off 1 - On
  (setvar "DIMSE1"    (nth 49 dimvariableslist));;Suppress the first extension line 0 - Off 1 - On
  (setvar "DIMSE2"    (nth 50 dimvariableslist));;Suppress the second extension line 0 - Off 1 - On
  (setvar "DIMSOXD"   (nth 51 dimvariableslist));;Suppress outside dimension lines
  (setvar "DIMTAD"    (nth 52 dimvariableslist));;Dimension Text Vertical distance
  (setvar "DIMTDEC"   (nth 53 dimvariableslist));;Tolerance decimal places
  (setvar "DIMTFAC"   (nth 54 dimvariableslist));;Dimension text scale factor of fractions relative to text height
  (setvar "DIMTFILL"  (nth 55 dimvariableslist));;Text background enabled
  (setvar "DIMTFILLCLR" (nth 56 dimvariableslist));;Text background color 0: ByLayer, 256 ByBlock
  (setvar "DIMTIH"    (nth 57 dimvariableslist));;Text inside extensions is horizontal 0 - Off 1 - On
  (setvar "DIMTIX"    (nth 58 dimvariableslist));;Place text inside extensions 0 - Off 1 - On
  (setvar "DIMTM"     (nth 59 dimvariableslist));;Dimension Minus tolerance distance when used with dimtol, or dimlim
  (setvar "DIMTMOVE"  (nth 60 dimvariableslist));;Text movement
  (setvar "DIMTOFL"   (nth 61 dimvariableslist));;Force line inside extension lines 0 - Off 1 - On
  (setvar "DIMTOH"    (nth 62 dimvariableslist));;Text outside horizontal 0 - Off 1 - On
  (setvar "DIMTOL"    (nth 63 dimvariableslist));;Tolerance dimensioning 0 - Off 1 - On
  (setvar "DIMTOLJ"   (nth 64 dimvariableslist));;Tolerance vertical justification
  (setvar "DIMTP"     (nth 65 dimvariableslist));;Dimension Plus tolerance distance when used with dimtol, or dimlim
  (setvar "DIMTSZ"    (nth 66 dimvariableslist));;Tick size
  (setvar "DIMTVP"    (nth 67 dimvariableslist));;Text vertical position
  (setvar "DIMTXSTY"  (nth 68 dimvariableslist));;Text style
  (setvar "DIMTXT"    (nth 69 dimvariableslist));;Dimension text Height
  (setvar "DIMTZIN"   (nth 70 dimvariableslist));;Suppresses leading zeros in tolerance values
  (setvar "DIMUPT"    (nth 71 dimvariableslist));;User positioned text 0 - Off 1 - On
  (setvar "DIMZIN"    (nth 72 dimvariableslist));;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)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

 

Edited by Steven P
Link to comment
Share on other sites

Steven P yes can use Steal driven via lisp a few lines of code. Just demand load Steal 1st.

 

(If (not steal)(load "StealV1-8"))
;;  The following example will attempt to import Layers: 'Layer1' & 'Layer2', and all Dimension  ;;
;;  Styles beginning with 'DimStyle' (not case-sensitive) from the drawing:                      ;;
;;  'C:\My Folder\MyDrawing.dwg' into the current drawing.                                       ;;
;;                                                                                               ;;
;;  (Steal "C:\\My Folder\\MyDrawing.dwg"                                                        ;;
;;     '(                                                                                        ;;
;;          (                                                                                    ;;
;;              "Layers"                                                                         ;;
;;              ("Layer1" "Layer2")                                                              ;;
;;          )                                                                                    ;;
;;          (                                                                                    ;;
;;              "Dimension Styles"                                                               ;;
;;              ("DimStyle*")                                                                    ;;
;;          )                                                                                    ;;
;;      )                                                                                        ;;
;;  )     

 

  • Like 1
Link to comment
Share on other sites

@Steven P Had an issues with BircsCAD using command to change font styles. User would crash randomly. had something to do with updating all existing fonts at once. but didn't happen when using entmake. or typing it manually only in lisp. another example of how quirky command is.

 

Also don't forget to set your dimension font style.

(setvar 'DIMTXSTY myfont)

 

  • Like 1
Link to comment
Share on other sites

Thanks BigAl,  thats probably what the OP wants to do if they have a drawing with it all set up - keeps doing similar to what they are doing just now

 

 

 

Thanks MHUPP, so far I think making text styles via command has worked for me, you are right though, should entmake them (I'll add that to the list of things to do in todays Friday Meetings, might as well be productive)

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