Jump to content

DXFOUT


Juergen

Recommended Posts

Hi,

 

i use this code to select objects, copy them to 0,0 

and make a dxfout.

 

How can i erase the copy objects from 0,0 not the last selected?

 

Thanks for your info.

 

(defun c:DXFOUT ( / pt ss objekte text Name)
 
(if (and (princ "\n Select objects to copy to 0,0 ")
	   (setq ss (ssget "_:L"))
	   (setq pt (getpoint "\n Enter base point: "))
	   )
    (command "_copy" ss "" "_NONE" pt "_NONE" '(0.0 0.0 0.0))
    )
  ;(command "_.zoom" "_object" ss "")
  (if (and
       (sssetfirst nil (ssget "_P"))
      (setq
       text (if (setq text (car(nentsel "\nget text ")))(setq text (cdr(assoc 1 (entget text)))))
          Name (getfiled "Export save as: " (strcat (getvar "DWGPREFIX")(if text (strcat text ".dxf")  "")) "dxf" 1)
        )
      )
      (command "dxfout" Name "V" "2007" "O" "_P" "" "")
  )
  (command "._erase" "_object" ss "")
  ;(command "_.zoom" "v")
(princ)
  
)

 

Link to comment
Share on other sites

You could try adding something like this instead of your erase command - just ideas you'll have adjust it all to make it work

 

(setq sslen (sslength ss))
(setq acount 0)
(while (< acount sslen))
  (setq ss1 (ssget "L"))
  (command "._erase" "_object" ss1 "")
  (setq acount (1+ acount))
);end while

 

Link to comment
Share on other sites

Use this when exploding stuff and add them back to a Selection set. modified it to delete the items copied.

way it works. Think of the drawing as a list of items and when working on a drawing anything you create or manipulate gets put to the end of that list "last entity".

So you bookmark of the current "last entity" before you create anything new "copy" that then gets added to the end of the list. the while command is saying delete anything  on the drawings list but stop at the bookmarked last entity.

 

 

(defun c:DXFOUT (/ pt ss objekte text Name)
  (if (and (princ "\n Select objects to copy to 0,0 ")
           (setq ss (ssget "_:L"))
           (setq pt (getpoint "\n Enter base point: "))
      )
    (progn
      (setq LastEnt (entlast)) ;add this to delete anything after this point.
      (command "_copy" ss "" "_NONE" pt "_NONE" '(0.0 0.0 0.0))
    )
  )
  ;(command "_.zoom" "_object" ss "")
  (if (and
        (sssetfirst nil (ssget "_P"))
        (setq
          text (if (setq text (car (nentsel "\nget text "))) (setq text (cdr (assoc 1 (entget text)))))
          Name (getfiled "Export save as: " (strcat (getvar "DWGPREFIX") (if text (strcat text ".dxf") "")) "dxf" 1)
        )
      )
    (command "dxfout" Name "V" "2007" "O" "_P" "" "")
  )
  (if (setq en (entnext LastEnt)) 
    (while en
      (entdel en) ;Deletes everything that was copied up to the bookmarked LastEnt
      (setq en (entnext en))
    )
  )
  ;(command "._erase" ss "") ;dont need "_object" when using Selection Set
  ;(command "_.zoom" "v")
  (princ)
)

 

  • Like 1
Link to comment
Share on other sites

4 hours ago, Juergen said:

Hi mhupp,

 

thanks for your help.

 

My problem is, that the selected object is taken to dxfout.

Not that from 0,0.

What do I have to change?

 

I thought you just wanted to erase the copied items?

You can build a new selection set of the copied items by changing the 2nd part of what i added.

 

(defun c:DXFOUT (/ pt SS SS1 text Name)
  (if (and (princ "\n Select objects to copy to 0,0 ")
           (setq ss (ssget "_:L"))
           (setq pt (getpoint "\n Enter base point: "))
      )
    (progn
      (setq LastEnt (entlast))
      (command "_.Copy" SS "" "_non" PT "_non" '(0.0 0.0 0.0))
      (setq SS1 (ssadd))
      (if (setq en (entnext LastEnt))
        (while en
          (ssadd en SS1)
          (setq en (entnext en))
        )
      )
    )
  )
  ;(command "_.zoom" "_object" SS1 "") ; would zoom to copied items
  (setq text (car (nentsel "\nSelect Text: "))
        text (cdr (assoc 1 (entget text)))
        Name (getfiled "Export save as: " (strcat (getvar "DWGPREFIX") (if text (strcat text ".dxf") "")) "dxf" 1)
  )
  (if Name
    (command "dxfout" Name "V" "2007" "O" SS1 "" "")  ;dxfout copied items SS1
  )  
  (command "_.Erase" SS1 "") ;erase copies items SS1
  ;(command "_.zoom" "v")
  (princ)
)

 

This will create a selection set of SS1 of the copied entity's

Edited by mhupp
  • Like 1
Link to comment
Share on other sites

Beaten to it... I was about to say the same, copy the items,  create a selection set from them and carry on as before using the new set.

 

Below is pretty much the same as above, should work

 

(defun c:SPDXFOUT (/ pt ss objekte text Name)
  (if (and (princ "\n Select objects to copy to 0,0 ")
        (setq ss (ssget "_:L"))
        (setq pt (getpoint "\n Enter base point: "))
      )
    (progn
      (setq LastEnt (entlast)) ;add this to delete anything after this point.
      (command "_copy" ss "" "_NONE" pt "_NONE" '(0.0 0.0 0.0))
      (if (setq en (entnext LastEnt)) 
        (while en
          (setq ss1 (ssadd en ss1))
          (setq en (entnext en))
        )
      )
    )
  )
  (if (and
        (sssetfirst nil (ssget "_P"))
        (setq
           text (if (setq text (car(nentsel "\nget text ")))(setq text (cdr(assoc 1 (entget text)))))
           Name (getfiled "Export save as: " (strcat (getvar "DWGPREFIX")(if text (strcat text ".dxf")  "")) "dxf" 1)
        )
      )
    (command "dxfout" Name "V" "2007" "O" ss1 "" "")
  )
  (command "._erase" "_object" ss1 "")
)

 

 

Oh, I changed the LISP name, just don't like using the same as an actual command that's all

Edited by Steven P
Updted
  • Like 1
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...