Jump to content

Recommended Posts

Posted

I request help with a Lisp routine for a requirement to open set of drawings and delete objects in all layers except "CUT"

 

I have a folder which has several dxf files. needed action are

 

1. Open each file

2. Delete objects in all layers except layer CUT

3. Save the file in dxf

4. Close the file

5. Open next file and start from action number 1

 

 

Posted
9 hours ago, Sridhar said:

I request help with a Lisp routine for a requirement to open set of drawings and delete objects in all layers except "CUT"

 

I have a folder which has several dxf files. needed action are

 

1. Open each file

2. Delete objects in all layers except layer CUT

3. Save the file in dxf

4. Close the file

5. Open next file and start from action number 1

 

 

@Sridar , maybe by ODBX, but ODBX cannot do SSSGET , so it will have to loop all over the entities and erase whose ones that are not at layer CUT .  

 

Please refer to 

 

lee-mac ODBX

 

Please upload a few dxf files 

 

 

Posted

So we don't know your LISP abilities, which part do you need help with, or all of it?

 

Can yo make a LISP that will do what you want on a single drawing?

Do you need to know how to do this to many files, 

Do you want to know both.

 

 

Posted

This will select everything in the drawing except things on the cut layer& delete them. to feed to ODBX

 

(defun Delete-all-Cut (/ SS)
  (setq ss (ssget "_X" '((8 . "~Cut")))); select everything in the drawing except whats on the cut layer.
  (foreach ent (mapcar 'cadr (ssnamex ss)))
    (entdel ent) ;delete everything
  )
  (repeat 3 (vl-cmdf "_.Purge" "A" "*" "N")) ;purge 3 times.
)

 

Now if their are blocks on the cut layer that have entities inside them on another layer those won't be deleted.

  • Like 1
Posted
10 hours ago, mhupp said:

This will select everything in the drawing except things on the cut layer& delete them. to feed to ODBX

 

(defun Delete-all-Cut (/ SS)
  (setq ss (ssget "_X" '((8 . "~Cut")))); select everything in the drawing except whats on the cut layer.
  (foreach ent (mapcar 'cadr (ssnamex ss)))
    (entdel ent) ;delete everything
  )
  (repeat 3 (vl-cmdf "_.Purge" "A" "*" "N")) ;purge 3 times.
)

 

Now if their are blocks on the cut layer that have entities inside them on another layer those won't be deleted.

@mhupp  How about ODBX do not accept ?

 

Quote

Notes on Function Parameters

fun

A function requiring a single argument (the VLA Document Object)

The supplied function should take a single argument (the VLA Document Object for each drawing processed), and follow the 'rules' of ObjectDBX, that is:

No Selection Sets (use of ssget, ssname, ssdel etc)

Other topic , about wildcard. as I can see  ~  means all but not,  please refer where to see all other wildcards uses

  • Like 1
Posted (edited)

Booooooooooo guess you could always use a script.

Edited by mhupp
Posted

If no DXF has already been created in the chosen folder, this script with AcCoreConsole should work.
All you have to do in a new drawing is to copy/paste this code directly on the command line (validate if necessary after the last parenthesis pasted)
You will then have to select the folder and once validated the script starts in windows command terminal.
At the end the DXFs will be created in the chosen folder.

((lambda ( / f_exe ShlObj Folder FldObj Out_Fld file_scr file_bat)
  (vl-load-com)
  (setq f_exe (findfile "accoreconsole.exe"))
  (setq
    ShlObj (vla-getinterfaceobject (vlax-get-acad-object) "Shell.Application")
    Folder (vlax-invoke-method ShlObj 'BrowseForFolder 0 "" 0)
  )
  (vlax-release-object ShlObj)
  (if Folder
    (progn
      (setq
        FldObj (vlax-get-property Folder 'Self)
        Out_Fld (vlax-get-property FldObj 'Path)
      )
      (vlax-release-object Folder)
      (vlax-release-object FldObj)
    )
  )
  (setq file_scr (open (strcat (getvar "ROAMABLEROOTPREFIX") "support\\update.scr") "w"))
  (write-line "((lambda ( / flag lay e)" file_scr)
  (write-line "(setq flag T) (while (setq lay (tblnext \"LAYER\" flag)) (setq e (entget (tblobjname \"LAYER\" (cdr (assoc 2 lay)))) flag nil) (entmod (subst (cons 62 (abs (cdr (assoc 62 e)))) (assoc 62 e) (subst '(70 . 0) (assoc 70 e) e))))" file_scr)
  (write-line "))" file_scr)
  (write-line "(command \"_.audit\" \"_Yes\")" file_scr)
  (write-line "(command \"_.-purge\" \"_Regapps\" \"*\" \"_No\")" file_scr)
  (write-line "(command \"_.-purge\" \"_All\" \"*\" \"_No\")" file_scr)
  (write-line "(command \"_.saveas\" \"_DXF\" \"_Version\" \"_LT2018\" \"_Objects\" (ssget \"_X\" '((8 . \"Cut\"))) \"\" \"16\" \"\")" file_scr)
  (close file_scr)
  (setq file_bat (open (strcat (getvar "ROAMABLEROOTPREFIX") "support\\update.bat") "w"))
  (write-line (eval (read "(strcat \"set accoreexe=\" \"\\\"\" f_exe \"\\\"\")")) file_bat)
  (write-line (eval (read "(strcat \"set source=\" \"\\\"\" Out_Fld \"\\\"\")")) file_bat)
  (write-line (eval (read "(strcat \"set script=\" \"\\\"\" (getvar \"ROAMABLEROOTPREFIX\") \"support\\\\update.scr\" \"\\\"\")")) file_bat)
  (write-line "FOR /f \"delims=\" %%f IN ('dir /b \"%source%\\\*.dwg\"') DO %accoreexe% /i \"%source%\\%%f\" /s %script%" file_bat)
  (close file_bat)
  (startapp (strcat (getvar "ROAMABLEROOTPREFIX") "support\\update.bat"))
  (princ"\Job finished")
  (prin1)
))

 

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