AutoLISP.com Forum Index  

Go Back   AutoLISP.com Forum Index > AutoCAD > AutoLISP

AutoLISP Ask questions, give examples or troubleshoot your lisp programs. Feel free to post your code here (NO commercial adversiting).

Reply
 
Thread Tools Display Modes
Old 02-09-2010, 04:01 AM   #11
klb546s
Junior Member
 
Join Date: Feb 2010
Posts: 14
Default

Hi Carl,
how about a function in the lisp program to plot a cross on the rect after I select it so that I can snap on to it easier.
Thanks
Regards,
kel be
klb546s is offline   Reply With Quote
Old 02-09-2010, 04:27 AM   #12
CarlAK
Senior Member
 
Join Date: Jan 2009
Location: Anchorage, Alaska
Posts: 203
Default

This one returns center point of rectangle. Call with 'rmp while drawing/stretching.
You may want to rename it for easier keystrokes.

Code:
(defun c:rmp ()
  (setq epick (car (entsel "Pick rectangle: ")))
  (setq ed (entget epick))
  (if (= "LWPOLYLINE" (cdr (assoc 0 ed)))
    (progn
      (setq VertList (cdrs 10 ed))
      (setq vertlist (cdr Vertlist));strip first gc10
      (setq pt1 (nth 0 vertlist))
      (setq pt2 (nth 2 vertlist))
      (setq PtWorld
          (mapcar '(lambda (x)
                           (/ x 2)
                      )  
                 (mapcar '+ Pt1 Pt2)  
          )
     )
     (trans PtWorld 0 1)    )
      nil;if not a lwpolyline
  )
)
;;-------------------------
(defun cdrs (key lst / pair rtn);;M. Puckett
   (while (setq pair (assoc key lst))
      (setq rtn (cons (cdr pair) rtn)
         lst (cdr (member pair lst))
      )
   )
   (reverse rtn)
)

Last edited by CarlAK; 02-10-2010 at 02:13 PM. Reason: Update code for UCS use
CarlAK is offline   Reply With Quote
Old 02-09-2010, 08:29 AM   #13
klb546s
Junior Member
 
Join Date: Feb 2010
Posts: 14
Default

Hi Carl,
thanks for the input. Its a bit time consuming but its better than before.
I will still need to find a faster way later on.
Anyway thank you very much for your help.
Regards
kel be
klb546s is offline   Reply With Quote
Old 02-09-2010, 10:53 PM   #14
klb546s
Junior Member
 
Join Date: Feb 2010
Posts: 14
Default

Quote:
Originally Posted by CarlAK View Post
This one returns center point of rectangle. Call with 'rmp while drawing/stretching.
You may want to rename it for easier keystrokes.

Code:
(defun c:rmp ()
  (setq epick (car (entsel "Pick rectangle: ")))
  (setq ed (entget epick))
  (if (= "LWPOLYLINE" (cdr (assoc 0 ed)))
    (progn
      (setq VertList (cdrs 10 ed))
      (setq vertlist (cdr Vertlist));strip first gc10
      (setq pt1 (nth 0 vertlist))
      (setq pt2 (nth 2 vertlist))
      (mapcar '(lambda (x)
                  (/ x 2)
               )
                 (mapcar '+ Pt1 Pt2)  
      )
    )
    nil;if not a lwpolyline
  )
)
;;-------------------------
(defun cdrs (key lst / pair rtn);;M. Puckett
   (while (setq pair (assoc key lst))
      (setq rtn (cons (cdr pair) rtn)
         lst (cdr (member pair lst))
      )
   )
   (reverse rtn)
)
Hi Carl,
why is that the center point of the rect is not correct if the rect is not
horizontal? (the rect is rotated at an angle say 5 deg.)
Thanks and Best Regards
kel be
klb546s is offline   Reply With Quote
Old 02-10-2010, 12:31 AM   #15
CarlAK
Senior Member
 
Join Date: Jan 2009
Location: Anchorage, Alaska
Posts: 203
Default

Not sure why center is not correct, I tried simple rectangle rotate & it seems to work.
now if you rotate the UCS, yes that would cause a problem. The code above was fixed to convert World to UCS coordinates, using the 'trans' function.

the following was replaced:
(mapcar '(lambda (x)
(/ x 2)
)
(mapcar '+ Pt1 Pt2)
)

-with-
Code:
(setq PtWorld
   (mapcar '(lambda (x)
                  (/ x 2)
               )
                 (mapcar '+ Pt1 Pt2)  
      )
)
(trans PtWorld 0 1)
And back to the automatic centering of lines in rectangles, try the attached. It requires user to select just the rectangles, it will center any lines that cross it.
Attached Files
File Type: lsp Sqli.lsp (2.2 KB, 3 views)

Last edited by CarlAK; 02-10-2010 at 02:16 PM. Reason: **refered to updated code**
CarlAK is offline   Reply With Quote
Old 02-10-2010, 07:39 AM   #16
klb546s
Junior Member
 
Join Date: Feb 2010
Posts: 14
Thumbs up Automatic centering of lines in rectangles

Hi Carl,
Thanks for the feedback. It works just as what I expected.
Will try out on more examples later.
See you....
Regards.
kel be
klb546s is offline   Reply With Quote
Old 02-24-2010, 09:01 AM   #17
klb546s
Junior Member
 
Join Date: Feb 2010
Posts: 14
Question If the lines are not hatched.

Quote:
Originally Posted by CarlAK View Post
kel be,

Try the attached lisp. The destination layer for the line can be edited in the code.

hope this helps, let me know if questions.

Carl
Hi Carl,
If the lines are not filled with hatch (becomes two single line) how do you change the autolisp program (attached) to draw a line between the 2 single line.

Thanks.
Regards
kel be
klb546s is offline   Reply With Quote
Old 02-26-2010, 03:13 AM   #18
CarlAK
Senior Member
 
Join Date: Jan 2009
Location: Anchorage, Alaska
Posts: 203
Default

Would not be easy to change the routine which is set up to recognize hatch geometry, to also recognize an assortment of lines. If user would choose "hatch" or "lines", then pick 2 lines at a time, that would be a fairly simple change. It would take some time to write the code to sort a group of lines, determine how to pair them up for drawing a midline. I would leave that up to you or some other volunteer
CarlAK is offline   Reply With Quote
Old 02-26-2010, 08:10 AM   #19
klb546s
Junior Member
 
Join Date: Feb 2010
Posts: 14
Default Mid line

HI Clark,
thanks for the prompt reply. Appreciate your feedback.
I have a simple lisp program that needs to select the 2 lines manually
to draw the mid line (see attached file).
What if we specify a condition that thickness of the line must meet
a certain criteria for example not more than a certain value,
then is it possible to group them?
Just an idea.
Thanks and Regards
kel be
Attached Files
File Type: lsp mid.lsp (982 Bytes, 5 views)
klb546s is offline   Reply With Quote
Old 02-26-2010, 08:12 PM   #20
CarlAK
Senior Member
 
Join Date: Jan 2009
Location: Anchorage, Alaska
Posts: 203
Default

I ran your routine and it works OK - but I had to turn off osnaps. Also if lines are drawn in opposite directions it didn't work correctly.

You could use a closeness tolerance like you suggest, and only draw midlines for lines within that tolerance.

If lines are always about the same length, you could compare midpoints for the spacing tolerance. So perhaps make a selection set; and make a list of midpoint coordinates. Compare first midpoint to each other to find one within the tolerance. call line-drawing subroutine for 2 lines. remove lines from selection set. If no line meets tolerance, remove just that one line from set.
Repeat until no further "matches".
CarlAK is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:45 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright © 2010, AutoLISP.com
All Rights Reserved