Automatically change DGN linetypes to ACAD linetypes of any layers in drawing

Automatically change DGN linetypes to ACAD linetypes of any layers in drawing

Anonymous
Not applicable
2,028 Views
11 Replies
Message 1 of 12

Automatically change DGN linetypes to ACAD linetypes of any layers in drawing

Anonymous
Not applicable

Hi,

 

I want to automatically change DGN linetypes to ACAD linetypes of any layers in a drawing (so change not based on layername)

 

I tried to change an existing LISP but it changes all layers to continuous and I don't know how to group all possible DGN styles in the code to change to their ACAD linetype versions.

I probably need to remove "lt continuous" but I don't know what else I need to modify.

 

Thx,

 

Bart

 

CODE:

 

(defun c:CALLT (/ lt cl l e)
  ;; based on CALP LISP by Tharwat 19.Sep.2013    ;;

  (setq lt "dashed" ;; LineType     ;;
  )
  (if (not (tblsearch "LTYPE" lt))
    (vla-load
      (vla-get-Linetypes
        (vla-get-ActiveDocument
          (vlax-get-acad-object)
        )
      )
      lt
      "acadiso.lin"
    )
  )

;; Change Linetype=DGN Style 2 of any layer UNDER CONSTRUCTION - Start ;;

  (while (setq l (tblnext "LAYER" (null l)))
    (if (wcmatch (cdr (assoc 2 l)) "*")
      (progn
        (setq e (entget (tblobjname "LAYER" (cdr (assoc 2 l))))
              e (subst (cons 06
                             (if (and lt (tblobjname "DGN Style 2" lt))
                               lt
                               "Continuous"
                             )
                       )
                       (assoc 06 e)
                       e
                )
        )
        (entmod e)
      )
    )
  )

;; Change Linetype=DGN Style 2 of any layer UNDER CONSTRUCTION - End ;;




  (princ)
)
(vl-load-com)
Accepted solutions (1)
2,029 Views
11 Replies
Replies (11)
Message 2 of 12

Satoews
Advocate
Advocate
;CODING BEGINS HERE

(defun c:ColorToLayer ()

  (setq originalLineStyle "DGN style 2")
  (setq newLineStyle "continuous")

  ;clear the loop control variables
  (setq	i 0 n 0)

  ;get the selction set
  (setq sel (ssget "x"))

  ;get the number of objects
  (setq n (sslength sel))

  ;start the loop
  (repeat n

    	;get the entity name
	(setq entity (ssname sel i))

	;now get the entity list
    	(setq name (entget entity))col

	;if not Bylayer
	(if (not (assoc 6 name))

	  ;do the following
	  (progn

		;retrieve the layer name
		(setq layer (cdr (assoc 8 name)))

		;get the layer data
		(setq layerinf (tblsearch "LAYER" layer))

		;extract the default layer colour
		(setq layercol (cdr (assoc 6 layerinf)))

		;construct an append the new list
		(setq name (append name (list (cons 6 layercol))))

		;update the entity
		(entmod name)

		;update the screen
		(entupd entity)

	        (if (eq layercol originalLineStyle)
		  (entmod (subst (cons 6 newLineStyle) (assoc 6 name) name)))

	   );progn

	(if
	  (= (cdr (assoc 6 name)) originalLineStyle)
	  (entmod (subst (cons 6 newLineStyle) (assoc 6 name) name))));if


	;increment the counter
	(setq i (1+ i))

  ;loop
  );repeat

(princ)

)colo;defun

(princ)

;CODING END HERE

Original code taken from afralisp tutorial here and modified. 

 

Try this change the originallinestyles and newlinestyles to your choosing.

Shawn T
0 Likes
Message 3 of 12

Satoews
Advocate
Advocate
;CODING BEGINS HERE

(defun c:changeStyleToStyle ( / originalLineStyle newLineStyle sel n i entity layer name layerinf layercol )

  ;set the orginal style the program will look for.
  (setq originalLineStyle "DGN style 2")

  ;set the new line style the program will change to.
  (setq newLineStyle "continuous")

  ;clear the loop control variables
  (setq	i 0 n 0)

  ;get the selction set
  (setq sel (ssget "x" '((410 . "model"))))

  ;get the number of objects
  (setq n (sslength sel))

  ;start the loop
  (repeat n

    	;get the entity name
	(setq entity (ssname sel i))

	;now get the entity list
    	(setq name (entget entity))col

	;if not Bylayer
	(if (not (assoc 6 name))

	  ;do the following
	  (progn

		;retrieve the layer name
		(setq layer (cdr (assoc 8 name)))

		;get the layer data
		(setq layerinf (tblsearch "LAYER" layer))

		;extract the default layer colour
		(setq layercol (cdr (assoc 6 layerinf)))

		;construct an append the new list
		(setq name (append name (list (cons 6 layercol))))

		;update the entity
		(entmod name)

		;update the screen
		(entupd entity)

                ;if the oldstyle is found in the entity without prior layerstyle info, it changes to the new line style.
	        (if
                  (eq layercol originalLineStyle)
		  (entmod (subst (cons 6 newLineStyle) (assoc 6 name) name)))

	   );progn

        ;if and entity if found with layer linestyle info and has the original line style, it is changed to the new line style.
	(if
	  (= (cdr (assoc 6 name)) originalLineStyle)
	  (entmod (subst (cons 6 newLineStyle) (assoc 6 name) name))));if


	;increment the counter
	(setq i (1+ i))

  ;loop
  );repeat

(princ)

)colo;defun

(princ)

(defun c:s2s ()
  (c:changeStyleToStyle)
)
;CODING END HERE

Edit 2: More work on the code.

 

 

Shawn T
Message 4 of 12

hmsilva
Mentor
Mentor

@Anonymous wrote:

Hi,

 

I want to automatically change DGN linetypes to ACAD linetypes of any layers in a drawing (so change not based on layername)

 

I tried to change an existing LISP but it changes all layers to continuous and I don't know how to group all possible DGN styles in the code to change to their ACAD linetype versions.

...

 


Hello Bart,

 

I'm not a Bentley user, and i don't know what kind of linetype microstation linetypes are...

If you want some help on this, try to post the microstation linetypes you have in the DGN's, and the AutoCAD linetype that will replace the DGN linetype
i.e.
"DGN Style 0" -> Continous
"DGN Style 1" -> Dot
"DGN Style 2" -> Hidden
and so on...

 

Do you use 'acad.lin' or 'acadiso.lin'?

 

Henrique

EESignature

0 Likes
Message 5 of 12

Anonymous
Not applicable

Hi,

 

Thx for this LISP.

 

Do you also know a LISP to just change the linetypes of layers (with linetype DGN Style X) automatically to their my self chosen ACAD linetype versions instead of changing it manually in layer properties manager?

 

Thx,

 

Bart

 

 

0 Likes
Message 6 of 12

Anonymous
Not applicable
Hello Henrique,

I want to use the LSIP to easily make a decent XREF of an architecture DGN drawing (Microstation) converted to DWG where the linetypes are still DGN linetypes.

I use acadiso.lin
0 Likes
Message 7 of 12

hmsilva
Mentor
Mentor

@Anonymous wrote:
Hello Henrique,

I want to use the LSIP to easily make a decent XREF of an architecture DGN drawing (Microstation) converted to DWG where the linetypes are still DGN linetypes.

I use acadiso.lin

Hi Bart,

what I was trying to say in my previous was:

as we are not Bentley users, we need that you tell us what are the names of the DGN linetypes, and which linetype from AutoCAD will replace, as you would do manually in layer properties manager...

i.e.
"DGN Style 0" -> Continous
"DGN Style 1" -> Dot
"DGN Style 2" -> Hidden
and so on...

 

Making a code to change the DGN linetypes in layers, is easy, but we need that you tell us the linetypes names to change, as in my previous example...

 

Henrique

EESignature

0 Likes
Message 8 of 12

Anonymous
Not applicable
Hi,

Yes I understood that 🙂
But If u make a LISP with a few DGN Style names as an example (like in your message) so I can add/change them myself in the LISP code it's OK for me 🙂
0 Likes
Message 9 of 12

hmsilva
Mentor
Mentor
Accepted solution

Untested...

 

(vl-load-com)
(defun c:demo (/ put_linetype linetypes ltyp ltyps)
    (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
    (setq linetypes (vla-get-linetypes adoc))
    (vlax-for ltyp (vla-get-linetypes adoc)
        (setq ltyps (cons (vla-get-name ltyp) ltyps))
    )
    (defun put_linetype (obj linetype linefile)
        (if (vl-position linetype ltyps)
            (vla-put-linetype obj linetype)
            (progn
                (vla-load linetypes linetype linefile)
                (setq ltyps (cons linetype ltyps))
                (vla-put-linetype lay linetype)
            )
        )
    )
    (vlax-for lay (vla-get-layers adoc)
        (cond ((wcmatch (setq ltyp (vla-get-linetype lay)) "DGN Style 0,DGN* 7")
               (vla-put-linetype lay "Continuous")
              )
              ((wcmatch (setq ltyp (vla-get-linetype lay)) "DGN Style 1,DGN* 3,DGN* 4")
               (put_linetype lay "DOT" "acadiso.lin")
              )
              ((wcmatch (setq ltyp (vla-get-linetype lay)) "DGN Style 2,DGN* 5,DGN* 6")
               (put_linetype lay "HIDDEN" "acadiso.lin")
              )
        )
    )
    (princ)
)

 

Hope this helps,
Henrique

EESignature

Message 10 of 12

Anonymous
Not applicable
Thanks Henrique, tested and works perfectly, I was also able to customize the code 🙂
0 Likes
Message 11 of 12

hmsilva
Mentor
Mentor

@Anonymous wrote:
Thanks Henrique, tested and works perfectly, I was also able to customize the code 🙂

You're welcome, stblb!
Glad I could help

Henrique

EESignature

0 Likes
Message 12 of 12

Anonymous
Not applicable

How do I change the code so it changes more than one linetype (linestyle) of an object to a new linetype (linestyle)?

 

DGN Style 0 -> Continuous

DGN Style 1 -> DOT2

DGN Style 2 -> HIDDEN2

...

0 Likes