Jump to content

copy and trim


blueshake

Recommended Posts

hi,all

the following codes are used to copy objects subjected to a circle user defined.

here comes my issue.see the pictures.

the blue ones are copied from the while, the green circle is a user defined zone.now I only want to trim the blue ones.not the green lines.how I can do

this? thank you for your time to read this.

1745_12884871409MUZ.png

 

(defun c:tt(/)
(setq pt (getpoint "\nget the center point."))
(command "_.circle" pt)
(princ (strcat "\ninput the radius of circle"))
(command pause "")	
(setq cir (entlast))
(setq r (cdr (assoc 40 (entget cir))))
(command "copy" "cp")
(setq n 0)
(repeat 180
	(command (polar pt (/(* 2 n pi)180) r))
	(setq n (+ n 1))	
)
(command "" "" pt (getpoint));ok ,finish the choose and copy 
;now how to get copied objects. and trim the things outside the circle.
;here I just want to trim the copied objects.


)

Link to comment
Share on other sites

If you're not using a TRIM command, kind of old, but this could be a starting point:

 

;;;Intersection Point Of LINE & CIRCLE
;;;ARG -> LINE ename CIRCLE ename
;;;RETURNS 2D point list or nil
(defun inters_line_circle (le ce / p10 p11 cen rad ppt pds osd ipt p2d)
 (setq p2d (lambda (p) (list (car p) (cadr p))))
 (and (= (type le) 'ENAME)
      (= (type ce) 'ENAME)
      (= "LINE" (cdr (assoc 0 (entget le))))
      (= "CIRCLE" (cdr (assoc 0 (entget ce))))
      (setq p10 (p2d (cdr (assoc 10 (entget le))))
            p11 (p2d (cdr (assoc 11 (entget le))))
            cen (p2d (cdr (assoc 10 (entget ce))))
            rad (cdr (assoc 40 (entget ce))))
      (cond ((equal p10 p11 1e-14))
            ((equal rad (distance cen p10) 1e-11)
             (setq ipt p10))
            ((equal rad (distance cen p11) 1e-11)
             (setq ipt p11))
            ((setq ppt (inters p10 p11 cen
                               (polar cen (+ (angle p10 p11) (* pi 0.5)) rad) nil))
             (and (setq pds (distance cen ppt))
                  (<= pds rad)
                  (setq osd (sqrt (- (* rad rad) (* pds pds)))
                        ipt (polar ppt (angle ppt p10) osd))))))
 ipt)

Link to comment
Share on other sites

@David

I dig into your codes, and found that it only work for lines.

Actually I want to write a detail view lisp.in this lisp ,we should

copy the objects surround by the circle user provide and trim the

things beyond the circle.:)

Link to comment
Share on other sites

hi,Lee

 

I put "extrim" in cad help documents and it said it is unknown command.maybe it is "trim"??

 

I want to write a detail view lisp.do you have any idea about this???

Link to comment
Share on other sites

after much try.here comes another codes.

but it trim everything beyond the circle.how can I just trim the copied ones.

(defun c:tt(/)
(defun *error* (msg)
	(setvar "osmode" oldOsmode)
)
(setq oldOsmode (getvar "osmode"))
(setvar "OSMODE" 0) 
(setq pt (getpoint "\nget the center point."))
(command "_.circle" pt)
(princ (strcat "\ninput the radius of circle"))
(command pause "")		(setq cir (entlast))
(setq r (cdr (assoc 40 (entget cir))))
(command "copy" "cp")
(setq n 0)
(repeat 180
	(command (polar pt (/ (* 2 n pi) 180) r))
	(setq n (+ n 1))	
)
(command "" "" pt pt)
(setvar "pickbox" 5)
(command "_.trim" cir "" "f")
(setq n 0)
(repeat 180
	(command (polar pt (* (/  (* 2 n) 180.0) pi) (* r 1.05)))
  	(setq n (1+ n))
)
 	(command "" "")
;(command "" "" pt (setq ptt (getpoint pt)));ok ,finish the choose and copy 
;now how to get copied objects. and trim the things outside the circle.
;here I just want to trim the copied objects.


)

Link to comment
Share on other sites

I am not sure of your request, but this may help you or approach the image to you .:)

 

(defun c:tt (/ pt rad cir all)
(command "_.circle" (setq pt (getpoint "\n Specify the center point."))
                            (setq rad (getdist pt "\n Get Circle Diameter ."))
                 )
 (setq cir (entlast)
)
 (princ "\n Select objects to be trimed")
       (setq all (ssget "_x" '((0 . "SPLINE,LWPOLYLINE,POLYLINE,LINE,CIRCLE"))))
(repeat (sslength all)
  (command "_.trim" cir "" all "")
  )
      (princ)
 )
 

 

Tharwat

Link to comment
Share on other sites

Crude example, but should help you with the trimming part.

(defun c:Test (/ lastEntity pt ent)
 (setq lastEntity (entlast))
 (if (or etrim (load "extrim.lsp" nil))
   (if (setq pt (getpoint "\nSpecify center point for circle: "))
     (progn
       (command "_.circle" "_non" pt)
       (while (eq 1 (logand 1 (getvar 'cmdactive))) (command PAUSE))
       (or (eq lastEntity (setq ent (entlast)))
           (etrim ent (polar (cdr (assoc 10 (entget ent))) 0. (1+ (cdr (assoc 40 (entget ent))))))
       )
     )
   )
   (alert "Express Tool \"Extrim\" does not exist!")
 )
 (princ)
)

Link to comment
Share on other sites

hi,all

I finally finish the program.:)

here are the codes.

(defun c:tt(/)
(defun *error* (msg)
	(setvar "osmode" oldOsmode)
)
(setq oldOsmode (getvar "osmode"))
(setvar "OSMODE" 0) 
(setq pt (getpoint "\nget the center point."))
(command "_.circle" pt)
(princ (strcat "\ninput the radius of circle"))
(command pause "")		
(setq cir (entlast))
(setq r (cdr (assoc 40 (entget cir))))
;(command "_.circle" pt 2*r "")
(setq enlargeCircle (entlast))
(command "_.move" enlargeCircle "" pt (setq ptt (getpoint pt)))
(command "copy" "cp")
(setq n 0)
(repeat 180
	(command (polar pt (/ (* 2 n pi) 180) r))
	(setq n (+ n 1))	
)
(command "" "" pt ptt)
(setvar "pickbox" 5)
(command "_.trim" cir "" "f")
(setq n 0)
(repeat 180
	(command (polar ptt (* (/  (* 2 n) 180.0) pi) (* r 1.01)))
  	(setq n (1+ n))
)
 	(command "" "")
(command "_.scale" "cp")
(setq n 0)
(repeat 180
	(command (polar ptt (/ (* 2 n pi) 180) r))
	(setq n (1+ n))
)
(command "" "" ptt 2 "")
 	(command "redarw")
(princ)
;(command "" "" pt (setq ptt (getpoint pt)));ok ,finish the choose and copy 
;now how to get copied objects. and trim the things outside the circle.
;here I just want to trim the copied objects.


)

Link to comment
Share on other sites

here are some explaination.

1.draw a circle and give the position you want to place the enlarged objects.

2.copy the objects surround by the circle and put them in the position you set in step 1

3.trim the things beyond the circle and enlarge them

but still something I can not figure out.when I move the circle, it can not show the circle in real time.it is strange.

Link to comment
Share on other sites

also I notice that

these codes I commented can not work

(command "_.move" enlargeCircle "" pt (setq ptt (getpoint pt)))

 

it can not draw a circle in real time as I expected.:(

Link to comment
Share on other sites

  • 1 month later...

I just want the objects inside the blue circle be enlarged . @alanjt. in your above way. can this be done? can you show me sth.

thanks.

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