Author Topic: Xlines at specific angles  (Read 5911 times)

0 Members and 1 Guest are viewing this topic.

Willie

  • Swamp Rat
  • Posts: 958
  • Going nowhere slowly
Xlines at specific angles
« on: January 05, 2016, 02:08:08 AM »
Hi all

I have quickly written the code below, and I still need to finish it.  I want to draw construction lines at specific angles.  The ccolor variable return "nil", but I will fix it later.

How do I see the construction line before I place it the first time?

Or is there an better way to achieve this?

Thanks!

Code: [Select]
(defun C:XL+75 (/)
  ( setq old_ccolor (getvar "ccolor"))
  ( setq old_clayer (getvar "clayer"))

  (command "-layer"
   "Make"
   "__Xline +75"
   "Color"
   "36"
   ""
   ""
   )

  (command "xline"
   "Ang"
   "75"
   (getpoint)
   )
 
 
  (setvar "ccolor" old_ccolor)
  (setvar "clayer" old_clayer)
  (princ)
  )
Soli Deo Gloria | Qui Audet Adipiscitur
Windows 8  64-bit Enterprise | Civil 3D 2015 and 2016| ArcGIS 10.1
Yogi Berra : "I'd give my right arm to be ambidextrous."

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Xlines at specific angles
« Reply #1 on: January 05, 2016, 03:33:36 AM »
Try using pause (or "\\") instead of (getpoint).
And use CECOLOR instead of CCOLOR.

Willie

  • Swamp Rat
  • Posts: 958
  • Going nowhere slowly
Re: Xlines at specific angles
« Reply #2 on: January 05, 2016, 07:07:15 AM »
Thanks for the help!
Soli Deo Gloria | Qui Audet Adipiscitur
Windows 8  64-bit Enterprise | Civil 3D 2015 and 2016| ArcGIS 10.1
Yogi Berra : "I'd give my right arm to be ambidextrous."

efernal

  • Bull Frog
  • Posts: 206
Re: Xlines at specific angles
« Reply #3 on: January 05, 2016, 01:10:46 PM »
Code - Auto/Visual Lisp: [Select]
  1. (DEFUN c:mxl (/ p1 p2 ang)
  2.   (IF (SETQ p1 (GETPOINT "\n-> Point for XLine : "))
  3.     (IF (SETQ ang (GETREAL "\n-> Angle for XLine : "))
  4.       (PROGN (SETQ p2 (POLAR (LIST 0.0 0.0 0.0) (* PI (/ ang 180.0)) 1.0))
  5.              (ENTMAKE (LIST (CONS 0 "XLINE")
  6.                             (CONS 100 "AcDbEntity")
  7.                             (CONS 8 "Nova")
  8.                             (CONS 62 1) ; 1 = red
  9.                             (CONS 100 "AcDbXline")
  10.                             (CONS 10 p1)
  11.                             (CONS 11 p2)
  12.                       )
  13.              )
  14.       )
  15.     )
  16.   )
  17.   (PRINC)
  18. )
  19.  
e.fernal

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Xlines at specific angles
« Reply #4 on: January 05, 2016, 01:32:36 PM »
I always found the built-in XLINE command to be quite temperamental when constructing an XLine from two points, and so I wrote my own version - perhaps it will prove useful for you too:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:x ( / i m p q v )
  2.     (setq i "Horizontal Vertical Exit"
  3.           m "\nPick 1st point for xline [Horizontal/Vertical/Exit] <Exit>: "
  4.     )
  5.     (if (not (tblsearch "layer" "XLINE"))
  6.         (entmake
  7.            '(
  8.                 (000 . "LAYER")
  9.                 (100 . "AcDbSymbolTableRecord")
  10.                 (100 . "AcDbLayerTableRecord")
  11.                 (002 . "XLINE")
  12.                 (070 .  0)
  13.                 (006 . "Continuous")
  14.                 (062 .  96)
  15.                 (290 .  0)
  16.                 (370 . -3)
  17.             )
  18.         )
  19.     )
  20.     (while
  21.         (progn (initget i) (and (setq p (getpoint m)) (/= "Exit" p)))
  22.         (cond
  23.             (   (= "Point" p)
  24.                 (setq v nil
  25.                       i "Horizontal Vertical Exit"
  26.                       m "\nPick 1st point for xline [Horizontal/Vertical/Exit] <Exit>: "
  27.                 )
  28.             )
  29.             (   (= "Horizontal" p)
  30.                 (setq v '(1.0 0.0 0.0)
  31.                       i "Vertical Point Exit"
  32.                       m "\nPick point for horizontal xline [Vertical/Point/Exit] <Exit>: "
  33.                 )
  34.             )
  35.             (   (= "Vertical" p)
  36.                 (setq v '(0.0 1.0 0.0)
  37.                       i "Horizontal Point Exit"
  38.                       m "\nPick point for vertical xline [Horizontal/Point/Exit] <Exit>: "
  39.                 )
  40.             )
  41.             (   v
  42.                 (entmake
  43.                     (list
  44.                        '(0 . "XLINE")
  45.                        '(8 . "XLINE")
  46.                        '(100 . "AcDbEntity")
  47.                        '(100 . "AcDbXline")
  48.                         (cons 10 (trans p 1 0))
  49.                         (cons 11 (trans v 1 0 t))
  50.                     )
  51.                 )
  52.             )
  53.             (   (and (setq q (getpoint "\nPick 2nd point: " p))
  54.                      (setq v (mapcar '- q p))
  55.                 )
  56.                 (entmake
  57.                     (list
  58.                        '(0 . "XLINE")
  59.                        '(8 . "XLINE")
  60.                        '(100 . "AcDbEntity")
  61.                        '(100 . "AcDbXline")
  62.                         (cons 10 (trans p 1 0))
  63.                         (cons 11 (trans v 1 0 t))
  64.                     )
  65.                 )
  66.                 (setq v nil)
  67.             )
  68.         )
  69.     )
  70.     (princ)
  71. )
« Last Edit: February 01, 2017, 01:11:42 PM by Lee Mac »

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: Xlines at specific angles
« Reply #5 on: January 26, 2016, 10:05:13 AM »
Quote from: Lee Mac
...so I wrote my own version - perhaps it will prove useful for you too:

What do the Swamp readers/authors think about this blog copying/stealing (pick your own term) code, routines, blog posts, etc from sources all over the Internet and posting them in a manner that more of less infers they are original. Sometimes, a link to the origin is added, but other times not.  That is why I'm asking - what is your opinion?


The author of that blog is a member of the Swamp.
I have tried on multiple occasions to contact this person, but never get a response.
Personally, I don't want my content reproduced, especially w/o my prior consent.
IMO - Providing a link to original content is one thing, with or without providing a small excerpt - but copying and pasting entire blog posts, images and all is beyond acceptable.


TIA folks.




cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Xlines at specific angles
« Reply #6 on: January 29, 2016, 07:50:29 PM »
Quote from: Lee Mac
...so I wrote my own version - perhaps it will prove useful for you too:

What do the Swamp readers/authors think about this blog copying/stealing (pick your own term) code, routines, blog posts, etc from sources all over the Internet and posting them in a manner that more of less infers they are original. Sometimes, a link to the origin is added, but other times not.  That is why I'm asking - what is your opinion?


The author of that blog is a member of the Swamp.
I have tried on multiple occasions to contact this person, but never get a response.
Personally, I don't want my content reproduced, especially w/o my prior consent.
IMO - Providing a link to original content is one thing, with or without providing a small excerpt - but copying and pasting entire blog posts, images and all is beyond acceptable.


TIA folks.

I personally don't mind, as long as credit is given. I don't necessarily think there needs to be a link to the source (I try to in my own code, but don't always manage to get the link in, but I do always try to give credit where credit is due). But I may or may not be in a minority on this one.

cwake

  • Guest
Re: Xlines at specific angles
« Reply #7 on: January 30, 2016, 01:01:41 AM »
That is why I'm asking - what is your opinion?

I can understand people not liking it, but I think that like most things in life and particularly with things online (eg. facebook, instagram, twitter, etc.) it's just something that goes with the territory. The only way to not be annoyed by the negative aspects is to never log on.

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: Xlines at specific angles
« Reply #8 on: February 01, 2016, 08:39:34 AM »
Fair enough guys.

I'm still sticking with ===> Copying and pasting code is one thing, but copying and pasting portions of a website and passing them off as his own original material is nothing more or less than simple theft.

ScottMC

  • Newt
  • Posts: 191
Re: Xlines at specific angles
« Reply #9 on: October 07, 2017, 12:59:47 AM »
Please.. add one more Lee, 'ang' Angular It would really helps having the angle xl too.  Been pushing myself to simplify xl's into [xh, xv and xx for ang] Thanks much

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Xlines at specific angles
« Reply #10 on: October 07, 2017, 07:39:32 AM »
Please.. add one more Lee, 'ang' Angular It would really helps having the angle xl too.  Been pushing myself to simplify xl's into [xh, xv and xx for ang] Thanks much

Try the following:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:x ( / a i m p q v )
  2.     (setq i "Horizontal Vertical Angle Exit"
  3.           m "\nPick 1st point for xline [Horizontal/Vertical/Angle/Exit] <Exit>: "
  4.     )
  5.     (if (not (tblsearch "layer" "XLINE"))
  6.         (entmake
  7.            '(
  8.                 (000 . "LAYER")
  9.                 (100 . "AcDbSymbolTableRecord")
  10.                 (100 . "AcDbLayerTableRecord")
  11.                 (002 . "XLINE")
  12.                 (070 .  0)
  13.                 (006 . "Continuous")
  14.                 (062 .  96)
  15.                 (290 .  0)
  16.                 (370 . -3)
  17.             )
  18.         )
  19.     )
  20.     (while
  21.         (progn (initget i) (and (setq p (getpoint m)) (/= "Exit" p)))
  22.         (cond
  23.             (   (= "Point" p)
  24.                 (setq v nil
  25.                       i "Horizontal Vertical Angle Exit"
  26.                       m "\nPick 1st point for xline [Horizontal/Vertical/Angle/Exit] <Exit>: "
  27.                 )
  28.             )
  29.             (   (= "Horizontal" p)
  30.                 (setq v '(1.0 0.0 0.0)
  31.                       i "Vertical Point Angle Exit"
  32.                       m "\nPick point for horizontal xline [Vertical/Point/Angle/Exit] <Exit>: "
  33.                 )
  34.             )
  35.             (   (= "Vertical" p)
  36.                 (setq v '(0.0 1.0 0.0)
  37.                       i "Horizontal Point Angle Exit"
  38.                       m "\nPick point for vertical xline [Horizontal/Point/Angle/Exit] <Exit>: "
  39.                 )
  40.             )
  41.             (   (= "Angle" p)
  42.                 (if (setq a (getorient "\nSpecify xline angle <back>: "))
  43.                     (setq v (list (cos a) (sin a) 0.0)
  44.                           i "Horizontal Vertical Point Angle Exit"
  45.                           m (strcat "\nPick point for " (angtos a) " xline [Horizontal/Vertical/Point/Angle/Exit] <Exit>: ")
  46.                     )
  47.                 )
  48.             )
  49.             (   v
  50.                 (entmake
  51.                     (list
  52.                        '(0 . "XLINE")
  53.                        '(8 . "XLINE")
  54.                        '(100 . "AcDbEntity")
  55.                        '(100 . "AcDbXline")
  56.                         (cons 10 (trans p 1 0))
  57.                         (cons 11 (trans v 1 0 t))
  58.                     )
  59.                 )
  60.             )
  61.             (   (and (setq q (getpoint "\nPick 2nd point: " p))
  62.                      (setq v (mapcar '- q p))
  63.                 )
  64.                 (entmake
  65.                     (list
  66.                        '(0 . "XLINE")
  67.                        '(8 . "XLINE")
  68.                        '(100 . "AcDbEntity")
  69.                        '(100 . "AcDbXline")
  70.                         (cons 10 (trans p 1 0))
  71.                         (cons 11 (trans v 1 0 t))
  72.                     )
  73.                 )
  74.                 (setq v nil)
  75.             )
  76.         )
  77.     )
  78.     (princ)
  79. )

ScottMC

  • Newt
  • Posts: 191
Re: Xlines at specific angles
« Reply #11 on: October 08, 2017, 08:44:41 PM »
Really appreciate it. Wrote and currently using the three most used 'xh as>[xl h], xv as>[xl v], and xx as>[xl a]' on there own. Attempted to write these into one page of code and won't work ... so I made individuals. I've yet to do that [[STUDY]] Your code acts just like mu; xl [multiple xline] and now realize that using the 'linetype' as 'hidden' causes osnap not to work with the blanks in hidden line. Thanks again. Here's one of the three I'm using..

 (defun C:xh (/  lyr)    ;;horizontal xline
    (setq lyr (getvar 'clayer))
    (command "_.-layer" "_M" "XLINE" "" "_.XLINE" "_h")
    (while (< 0 (getvar 'cmdactive)) (vl-cmdf "\\"))
    (setvar 'clayer lyr)
    (princ)
  )

Q: Post a link to help me understand the connection between: (getpoint..  &  "\\"  if there is. Thanks
« Last Edit: October 08, 2017, 09:25:36 PM by ScottMC »

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Xlines at specific angles
« Reply #12 on: October 09, 2017, 09:11:14 AM »
Nice code Lee, it could teach one to work with vectors! :thumbsup:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Xlines at specific angles
« Reply #13 on: October 09, 2017, 02:57:50 PM »
Q: Post a link to help me understand the connection between: (getpoint..  &  "\\"  if there is.

"\\" in AutoLISP is interpreted as a single backslash.

When passed to an AutoCAD command, the backslash is a macro operator indicating that the command should pause for user input:

http://help.autodesk.com/view/ACD/2018/ENU/?guid=GUID-D991386C-FBAA-4094-9FCB-AADD98ACD3EF

getpoint is an AutoLISP function:

http://help.autodesk.com/view/ACD/2018/ENU/?guid=GUID-445F32F0-8A9D-4E1D-976F-DE87CC5267D0

Nice code Lee, it could teach one to work with vectors! :thumbsup:

Thanks Grrr!  :-)