Jump to content

How to copy poly from one drawing to another during lisp program


Recommended Posts

Posted

Hello.

Ok, so I have this problem, I need to 'copybase 0,0' created poly via entmake function, and 'pasteclip 0,0' to another dwg that I would open during looping lisp, and then close that other dwg, return to original dwg and continue my lisp. Is that possible? I've tried copying it like you can see and manually pasting, but it's not working...

 

(defun	  c:crssv
(/ x	    y	     z	      f	       ypt	xpt	 vpt
   ent	    bpnt     inspt    n	       choice	pntx	 pnt
   alignment	     pntcsv   loop     profile	intlst	 distAtPoint
   distAt2Point
  )
;;;******************************************************************
  (defun *error*(emsg)
    (if	(or (= emsg "quit / exit abort")
	    (= emsg "bad argument type: lselsetp nil")
	) ;_ _ or
      (princ "")
      (princ emsg)
    ) ;_ if
    (setq loop nil
    ) ;_  setq
    (setvar 'OSMODE osm)
    (setvar 'ATTDIA atd)
    (command-s "ucs" "w")
    (setvar 'CMDECHO cmd)
    (gc)
  ) ;_ defun


  (setq cmd (getvar 'CMDECHO))
  (setvar 'CMDECHO 0)
  (setq atd (getvar 'ATTDIA))
  (setvar 'ATTDIA 0)
  (vl-cmdf "-units" "2" "" "1" "0" "0" "")
  (setq osm (getvar 'OSMODE))
  (vl-load-com)
  (SETVAR 'OSMODE 40)
  (setq loop T)
  (setq	alignment
	 (vlax-ename->vla-object
	   (ssname
	     (lm:ssget "\nSelect an alignment : "
		       '(":S" ((0 . "LINE,LWPOLYLINE,POLYLINE")))
	     ) ;_ _ lm:ssget
	     0
	   ) ;_ ssname
	 ) ;_ vlax-ename->vla-object)
  ) ;_ setq
  (while loop
    (setq profile
	   (vlax-ename->vla-object
	     (ssname
	       (lm:ssget "\nSelect profile : "
			 '(":S" ((0 . "LINE,LWPOLYLINE,POLYLINE")))
	       ) ;_ _ lm:ssget
	       0
	     ) ;_ ssname
	   ) ;_ vlax-ename->vla-object)
    ) ;_ setq
    (setq bpnt nil)
    (setq intlst (gr3 (vlax-invoke
			alignment
			'IntersectWith
			profile
			acExtendOtherEntity
		      ) ;_  vlax-invoke
		 ) ;_  gr3
	  bpnt	 (car intlst)
    ) ;_  setq
    (setq distAtPoint
	   (vlax-curve-getDistAtPoint
	     alignment
	     (vlax-curve-getClosestPointTo alignment bpnt T)
	   ) ;_  vlax-curve-getDistAtPoint
    ) ;_  setq
    (setq distAt2Point (+ 0.001 distAtPoint))
    (setq ucspnt (vlax-curve-getPointAtDist alignment distAt2Point)) ;_ _ setq
    (setq pnt nil
	  vpt nil
	  ypt nil
	  xpt nil
	  pntpr	nil
	  pntsset nil
	  pntucssort nil
	  pntlist nil
    ) ;_ setq
    (setvar 'OSMODE 0)
    (setq pntsset
	   (lm:ssget
	     "\nSelect points : "	;   ss izabranih toèaka
	     '(((0 . "POINT")))
	   ) ;_ _ lm:ssget
    ) ;_ _ setq
    (setq i 0)
    (repeat (sslength pntsset)
      (setq pntlist			;  lista izabranih toèaka
	     (cons (cdr	(assoc
			  10
			  (entget (ssname pntsset i)) ;_ _ entget
			) ;_ _ assoc
		   ) ;_ _ cdr
		   pntlist
	     ) ;_ _ cons
      ) ;_ setq	    	  
      (setq i (1+ i))
    ) ;_ _ repeat

;************************
    (GetPointsProjectedOnLine profile pntlist)

    (vl-cmdf "ucs" "3p" bpnt ucspnt "") ;_ vl-cmdf
    (vl-cmdf "ucs" "z" "90")

    (setq pntpr
	   (mapcar			; privremena lista translatiranih toèaka 
	     '(lambda (x) (trans x 0 1)) ;_ _ lambda
	     pntlist
	   ) ;_ _ mapcar
    ) ;_ _ setq
    (setq pntlist nil)
    (setq pntucssort
	   (vl-sort
	     pntpr			;  pntpr ali sortirano od lijeva na desno
	     (function
	       (lambda (x1 x2) (< (car x1) (car x2))) ;_ _ lambda
	     ) ;_ _ function
	   ) ;_ _ vl-sort
    ) ;_ _ setq

;*************************
    (vl-cmdf "ucs" "")			
    (setvar 'OSMODE 0)
    (vl-cmdf "circle" bpnt 3)
    (setq pntcsv (reverse pntcsv))
    (setvar 'OSMODE 0)
    (entmake
      '((0 . "POLYLINE"); Object type*******************************************
	;(66 . 1)
       )
    ) ;_ entmake
    (setq n 0)
    (repeat (length pntucssort)
      (setq ent (nth n pntucssort))
      (setq xpt (caddr ent))
      (setq ypt (car ent))
      (setq vpt (list ypt xpt 0.000))
      (entmake
	(list '(0 . "VERTEX")		; Object type
	      (cons 10 vpt)
	) ;_ list
      ) ;_ entmake
      (setq n (1+ n))
    ) ;_ repeat
    (entmake '((0 . "SEQEND")))
    (setq n 0)
	
	
	;HERE I NEED THAT 
	
	
    (command "_.copybase" "0,0" (entlast) "")
    (entdel (entlast))
  ) ;_ while
  (setvar 'CMDECHO cmd)
  (setvar 'OSMODE osm)
)




;**************************************************************
; funkcija vraæa 2D udaljenost meðu toèkama ignorirajuæi visinu
(defun Get2Ddistance (a b / dst)
  (setq	dst (sqrt (+ (expt (- (car a) (car b)) 2)
		     (expt (- (cadr a) (cadr b)) 2)
		  ) ;_ +
	    ) ;_ sqrt
  ) ;_ setq
) ;_ defun

;*******************************************************************************
; funkcija vraca skup tocki na liniji l najbliže svakoj tocki iz selekcije pntss

(defun GetPointsProjectedOnLine	(l pntlist / nearest_pnt h ent num)
  (setq num 0)
  (repeat (length pntlist)
    (setq ent (nth num pntlist))
    (setq nearest_pnt (vlax-curve-getClosestPointTo l ent T)) ;_ setq
    (setq h (caddr ent))
    (setq nearest_pnt (reverse (cons h (cdr (reverse nearest_pnt)))))
    (setq pntx (cons nearest_pnt pntx))
    (setq num (1+ num))
  ) ;_ _ repeat
) ;_ defun

;*******************************************************
; pretvara listu koordinata u dotted parove po 3 koord
(defun gr3 (lst / rtn)			
  (repeat (/ (length lst) 3)
    (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)
	  lst (cdddr lst)
    ) ;_  setq
  ) ;_  repeat
  (reverse rtn)
) ;_  defun


;********************************************************
;thanx Lee
(defun lm:ssget	(MSG PARAMS / SEL)	
  (princ MSG)
  (setvar 'NOMUTT 1)
  (setq SEL (vl-catch-all-apply 'SSGET PARAMS))
  (setvar 'NOMUTT 0)
  (if (not (vl-catch-all-error-p SEL))
    SEL
  ) ;_ _ IF
) ;_ _ DEFUN


;********************************************************

(princ "\n...Type CRSSV to initiate...") ;_ princ

 

Posted

Problem with a straight LISP is that when you move from one drawing top another the running LISP stops.

 

You can do this with a script though, not sure if you have looked into that? Lee Mac has a script writer routine and there are a few others out there. (I have one but is in a continual state of not quite ready to put onto the internet as I think of other stuff to do to it).

 

So if I read your question right, your entmake line (or object, could be anything - but polyline in your case) is created in drawing 1, and you need a copy in drawing 2? You could just do the entmake in drawing 2 without the copybase.

 

What my script LISP does is write to a text file the commands I want to use, then calls that as a script file, the orignal drawing runs the LISP, but the script lets you open other drawings (saved in the windows TEMP file folder, can be deleted from there as you want and named according to the LISP that created it). I haven't worked out how to do this with a drawing that is open already, drawing 2 needs to be closed to work well.

 

Based on that you might create a temporary script text file with a LISP in it to create your entity (see the internet on how a LISP can make a text file, saved with a *.scr suffix), then in your script file do an open file, run the temporary LISP, save file, close file. Then all you need to do is to get that to run from your LISP above... easy? 

 

However it is Sunday, CAD is off just now, so I can't make anything up today. Someone else might have something to copy and paste or be inspired by above to make something up for you

Posted (edited)

Agree with Steven P use a script, not tested.

 

Open dwg2

(load "your lisp") make sure you have the defun call as last line eg (c:runmylisp) this will run it

Close Y

 

It should return back to your original dwg.

 

Edited by BIGAL
Posted

I'm sorry for late response, for I wasn't notified of any responses...thank you for responses, I've heard of scripts but am unfamiliar with them and wanted to see if it could be done without them

Posted

ok, so lets say I created script that I invoke in drawing 2, but how to continue lisp going in drawing 1 because when I switch dwg it shuts down?

Posted

I am not an expert at Scripts, I built something that works for me, but if you do everything in the script file than it will open another, close it and , return to the original drawing and continue.

 

So what I might do is something like this in a script file:

- Drawing A, do some LISPs and stuff getting the info for the lines and whatever 

- Open drawing B, do some LISPs in that

- Save drawing B, close drawing B

[returned to drawing A now)

- Open modify, save close drawing C

[returned to drawing A now)

.. and so on

[returned to drawing A now)

If you want do LISPs in drawing A again

 

If the original LISP run on drawing A is needed to continue at the end of opening and closing the other then you might need to split it into 2 LISPs, say MyLISPA and MyLISPB, running 'A' at the start and 'B' at the end

 

 

 

Someone might have an example script handy to show you an example, I'll see if I can make one up this afternoon as an example for you

Posted (edited)

thank you for that, my thoughts were similar but problem is I have to open specific dwgs in which to copy the polies (dwgs are not predetermined ) so is it possible that I choose which dwg will be opened?

What you're saying is that the whole lisp must be in a script...

Edited by Tomislav
Posted

So this is an example of the Script I make up, if you can write to a text file then all the parts are out there that you need, for example Lee Mac has a LISP top select files which you can use to open / close / take references from and so on

 

 

LOAD "C:\\Users\\Me\\AppData\\Local\\Temp\\batchscrlisps.lsp"  ;;loads a LISP file in case it isn't loaded
LOAD "C:\USERS\Me\DESKTOP\AUTOCAD\AUTOCAD LISPS\ZOOMS.LSP"     ;;loads another LISP file in case it isn't loaded
ZA                                                             ;;LISP command as you'd type into command line, here ZA = Zoom All
layout1                                                        ;;Another LISP commmand as above, here switch to layout 1
(c:batchsaveas  "" "" "" "")                                   ;;Another LISP commmand.. here save as (without dialogue box)
_.OPEN "C:\Users\Me\Drawings\ABC-EFG-111_P1.dwg"               ;;Open drawing B
LOAD "C:\\Users\\Me\\AppData\\Local\\Temp\\batchscrlisps.lsp"  ;;As before for these 5 lines
LOAD "C:\USERS\ME\AUTOCAD\AUTOCAD LISPS\ZOOMS.LSP"
ZA
layout1
(c:batchsaveas  "" "" "" "")
_.OPEN "C:\Users\Me\Drawings\EFG-HIJ-222_P1.dwg"               ;;Open drawing C
(vla-close (vla-item (vla-get-documents (vlax-get-acad-object)) "ABC-DEF-111_P1.dwg") :vlax-false)  ;;Close drawing B
LOAD "C:\\Users\\Me\\AppData\\Local\\Temp\\batchscrlisps.lsp"  ;;as before
LOAD "C:\USERS\ME\AUTOCAD\AUTOCAD LISPS\ZOOMS.LSP"
ZA
layout1
(c:batchsaveas  "" "" "" "")
_.OPEN "Drawing1.dwg"
(vla-close (vla-item (vla-get-documents (vlax-get-acad-object)) "EFG-HIJ-222_P1.dwg") :vlax-false)   ;;Close drawing C
LOAD "C:\\Users\\Me\\AppData\\Local\\Temp\\batchscrlisps.lsp"  ;;I don't thinK I need these 6 lines... have to check anotherr time
LOAD "C:\USERS\ME\AUTOCAD\AUTOCAD LISPS\ZOOMS.LSP"
ZA
layout1
(c:batchsaveas  "" "" "" "")
(vla-SendCommand (vla-get-ActiveDocument (vlax-get-acad-object)) "(c:batchclose)")

 

This is saved in my temp file and is run with.. this is the key part maybe?

(command "_.SCRIPT" tempscript) ;;run script

 

where tempscript is the script file and file path

 

 

 

Look through this and other examples online and see where you get to, use write to a text file to create the script if you want to do it all through CAD

  • Like 1
Posted (edited)

the goat has something for this.

http://www.lee-mac.com/copytodrawing.html

 

Quote

This program enables the user to copy a selection of objects to a selected set of drawings, without opening the drawings in the AutoCAD Editor.

 

Edited by mhupp
  • Like 2
Posted

thank you for your ideas, unfortunately Lee's lisp is not adequate for my needs simply because copying it manually is faster, cause I need to create and copy one polyline to one dwg, and loop it, and Lee's lisp is good for large sets of drawings to copy to, and I would have to break the loop.

will take a look at your script Steven, thanx  

Posted
On 6/6/2022 at 10:25 PM, Tomislav said:

thank you for that, my thoughts were similar but problem is I have to open specific dwgs in which to copy the polies (dwgs are not predetermined ) so is it possible that I choose which dwg will be opened?

What you're saying is that the whole lisp must be in a script...

 

if dwgs are not predetermined, how about to use makeentmake.lsp

http://www.theswamp.org/index.php?topic=31145

 

This automatically creates the selected entity in Lisp code.

 

you can modify this to create a different lsp file for each part, 

and load the corresponding Lisp from each drawing.

It's far from automatic, but if there is a time gap between copybase and pastebase, 

this might be useful as an alternative to blocking it externally.

  • Agree 1
Posted

that could be useful, it's not for real time copy-paste as you said it, but for first creating and later inserting, thanx

Posted (edited)

I'm having problem with passing last created polyline in my lisp because (entlast) results in some other objects (look at my code), so how to do it?

 

never mind...solved it

Edited by Tomislav

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