Jump to content

Trim lines passing through a block?


WPerciful

Recommended Posts

I have a series of blocks that I am replacing via lisp routine. But the new blocks are wider than the old ones. So I wrote the routine below to trim the lines that extend into a block. It works intermittently when the block is horizontal. I haven’t added the code to trim the lines if it’s vertical yet because I can’t figure out why the code doesn’t consistently work. The code is below and the attached drawing files has the blocks I’m using as an example.

 

(defun trimblocklines ( ent / e d ins ero bw bh pt1 pt2 ss1 cnt sslen )
(setvar "cmdecho" 0)
(setq e ent
	d (entget e)
	ins (cdr (assoc 10 d))
	ero (* (dxf 50 d) (/ 180 pi))
	bw 0.25
	bh 0.125
	pt1 (list (- (nth 0 ins) (/ bw 2)) (- (nth 1 ins) (/ bh 2)) (nth 2 ins))
	pt2 (list (+ (nth 0 ins) (/ bw 2)) (+ (nth 1 ins) (/ bh 2)) (nth 2 ins))
	ss1 (ssget "_C" pt1 pt2 '((0 . "line")))
	cnt 0
	sslen (sslength ss1)
	ln_ents (list )
)
(command "circle" ins (list (+ (nth 0 ins) (/ bw 2)) (nth 1 ins)))
(setq cent (entlast))
(while (< cnt sslen)
	(setq ln_ents (append ln_ents (list (ssname ss1 cnt)))
		cnt (1+ cnt)
	)
)
(command "trim" cent ss1 "" (list (- (nth 0 ins) (- (/ bw 2) 0.01)) (nth 1 ins) 0.0) "")
(command "trim" cent ss1 "" (list (+ (nth 0 ins) (- (/ bw 2) 0.01)) (nth 1 ins) 0.0) "")
(entdel cent)
(setvar "cmdecho" 0)
(princ)
)

 

trimlines.dwg

 

Thank you

Edited by WPerciful
Fixed some code / removed a note in the code
Link to comment
Share on other sites

I think the extrim command might get the job done but it's a lisp so I cann't use it.

 

Is there a way to use the extrim command using vlisp?

 

(defun trimblocklines ( ent / e d ins ero bw bh pt1 pt2 ss1 cnt sslen )
(setvar "cmdecho" 0)
(setq e ent
 d (entget e)
 ins (cdr (assoc 10 d))
 ero (* (cdr (assoc 50 d))(/ 180 pi))
 bw 0.25
 bh 0.125
 pt1 (list (- (nth 0 ins) (/ bw 2)) (- (nth 1 ins) (/ bh 2)) (nth 2 ins))
 pt2 (list (+ (nth 0 ins) (/ bw 2)) (+ (nth 1 ins) (/ bh 2)) (nth 2 ins))
 ss1 (ssget "_C" pt1 pt2 '((0 . "line")))
 cnt 0
 sslen (sslength ss1)
 ln_ents (list )
)
(command "circle" ins (list (+ (nth 0 ins) (/ bw 2)) (nth 1 ins)))
(setq cent (entlast))
(while (< cnt sslen)
 (setq ln_ents (append ln_ents (list (ssname ss1 cnt)))
  cnt (1+ cnt)
 )
)
(command "extrim" cent "" (list (- (nth 0 ins) (- (/ bw 2) 0.01)) (nth 1 ins) 0.0) "")
(entdel cent)
(setvar "cmdecho" 0)
(princ)
)

 

:unsure:

Link to comment
Share on other sites

The TRIM command can be very temperamental when evaluated from a LISP program - I would personally suggest using the BREAK command instead.

 

Also, you should be aware that any active Object Snaps will affect the point supplied to the command - you should hence either temporarily disable Object Snap, or submit the "_non" or "_none" command modifier before supplying your points.

 

Perhaps my Automatic Block Break program can help you with the task.

 

Lee

Link to comment
Share on other sites

The TRIM command can be very temperamental when evaluated from a LISP program - I would personally suggest using the BREAK command instead.

 

Also, you should be aware that any active Object Snaps will affect the point supplied to the command - you should hence either temporarily disable Object Snap, or submit the "_non" or "_none" command modifier before supplying your points.

 

Perhaps my Automatic Block Break program can help you with the task.

 

Lee

 

 

Lee, your “Automatic Block Break” program is AWESOME. It does everything I need.

 

I have been working to replace many of our old blocks with new ones. The new blocks are wider. The only code I have left is the breaking of the lines. I am going to rewrite my routine to use the break command and add the “_non” command modifier before inputting the points.

I'll post the new code once I have it.

 

Thank you for all of the help!

Link to comment
Share on other sites

You can use extrim with lisp a bit of a gotcha though about using it.

(load "Extrim")
(etrim obj pt1) ; need to use etrim to pick cut obj and then a pt inside or out etc

Link to comment
Share on other sites

  • 1 month later...

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