Jump to content

Hi, I want to know if there is a lisp to merge or replace linetype styles in Autocad


Recommended Posts

Posted (edited)

I have a drawing where there are some linetypes and I want to replace all of them with HIDDEN2 (including objets into blocks), I found this code, but it only works in objets that are not into blocks.

 

Thanks! 

 

;Based on code by Tharwat, http://www.autolisp.com/forum/threads/774-linetype-change?p=2696&viewfull=1#post2696

(vl-load-com)

(defun c:LtMerge (/ *error* lto ltn fnd ss i sn name blocks)

 (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg)))
    (vla-endundomark acdoc)
    (princ))
  
  (if (not acdoc) (setq acdoc (vla-get-activedocument (vlax-get-acad-object))))
  (vla-startundomark acdoc)
  
  (if (and (not (eq (setq lto (strcase (getstring "\nSpecify OLD lineType: "))) ""))
	   (setq fnd (tblsearch "LTYPE" lto))
	   (not (eq (setq ltn (strcase (getstring "\nSpecify NEW lineType: "))) ""))
	   (setq fnd (tblsearch "LTYPE" ltn))
	   (setq ss (ssget "_X"))
	   (if (eq (getvar 'CELTYPE) ltn)
	     (setvar 'CELTYPE ltn)
	     T)
      )
    (repeat (setq i (sslength ss))
      (setq sn (ssname ss (setq i (1- i))))
      (if (eq (cdr (assoc 6 (entget sn))) lto)
	(vla-put-linetype (vlax-ename->vla-object sn) ltn))
      (if
	(and (eq (cdr (assoc 0 (entget sn))) "INSERT")
	     (not (member (setq name (cdr (assoc 2 (entget sn)))) blocks))
	)
	 (progn
	   (setq blocks (cons name blocks))
	   (vlax-for each (vla-item (vla-get-blocks acdoc) name)
	     (if (eq (vla-get-linetype each) lto)
	       (vla-put-linetype each ltn)))
	 )
      )
    )
  )
  (command "_.-PURGE" "_lt" lto "_n")
    
  (cond	((not ltn) (princ "\n LineType is nil "))
	((not fnd)
	 (princ "\n Couldn't find the Linetype or not loaded "))
  )

  (vla-regen acdoc AcallViewports)
  (vla-endundomark acdoc)
  (princ)
)

 

@Lee Mac

Edited by josue777torsan
Posted

don't know how to do it with lisp but you can just delete it from the linetype manager.  it should give you a warning saying if you delete this line type it will delete all entity's assigned it. or you can re assign a new line type to those entity's. or that's what it does in BricsCAD.

 

image.png.1dba019b4281b130f6448e70452f18e6.png

  • Like 1
Posted

Thanks, @mhupp, it looks great, but rather I'm looking for a free solution

Posted

That is a free solution type "linetype" to bring up the linetype manager in autocad should look like this.

 

image.png.3651a3a4533faf47290634029415dd2c.png

 

Select hidden 2 and delete in the top right.

 

 

  • Confused 1
Posted

Sorry, maybe I was not clear. I don't want to delete HIDDEN2, I want to replace with it all other linetypes (except Continuous), or merge them (like when merge layers)

 

  • Confused 1
Posted

Just quickly testing the code you posted, normally I would expect Tharwats code to be OK.

 

So made a block with 4 lines and also the same 4 lines not in a block.. and it appears to change the line type inside and outside he block as you were wanting.

Would you be able to post an example block that you are trying to update and perhaps a before and after type of thing?

  • Agree 1
Posted
8 minutes ago, Steven P said:

Just quickly testing the code you posted, normally I would expect Tharwats code to be OK.

 

So made a block with 4 lines and also the same 4 lines not in a block.. and it appears to change the line type inside and outside he block as you were wanting.

Would you be able to post an example block that you are trying to update and perhaps a before and after type of thing?

 

Oh! you are right, but I noticed that the LISP doesn't work in blocks into another block, maybe thats the main problem why I couldn't apply it 

Posted

OK we can have a think then how to add nested blocks to the routine,

 

I think there are a couple of if statements in there, one 'if' for outside of a block to change the line type,s one 'if' for inside a block to change the line type, it might be just as simple as looping through the nested blocks from there to change the line types

 

I'll have a think later

  • Like 1
Posted
2 hours ago, josue777torsan said:

Sorry, maybe I was not clear. I don't want to delete HIDDEN2, I want to replace with it all other linetypes (except Continuous), or merge them (like when merge layers)

 

 

No your not understanding me. By deleting the Hidden2 line type Autocad should ask you what do do with the entity's that have it assigned.

Either delete them The option you don't want  or Reassign them to a different line type aka merge them.

 

having trouble uploading the gif so use this link to see what im talking about.

https://ibb.co/q7k6Qg4

 

Posted

I see... but I'm afraid that's not possible in AutoCAD, I think that just works on BricsCAD

Posted

@josue777torsan , why not to upload a sample dwg? So all facts can be handled /

 

 

Posted
14 minutes ago, devitg said:

@josue777torsan , why not to upload a sample dwg? So all facts can be handled /

 

 

Sorry, I just test the code I posted first and magically works fine, in any case I've attached the lisp file and dwg file for you.
Thanks.

LTMerge test.dwg LTMerge.lsp

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