Author Topic: color  (Read 4068 times)

0 Members and 1 Guest are viewing this topic.

Jim Yadon

  • Guest
color
« on: August 29, 2005, 11:11:03 AM »
Can anyone help  me out with this minor problem? I'm sure it's easy but it seems to be vapor for me at the moment.

Code: [Select]
(defun jay-userdef_4_points()

  ;;;
  ;;;  this command needs to be completed!!!
  ;;;
 
  ;need to insert a line here to fetch the color and change the hard code at the end
  (setq jayudp1 (getpoint "\n Pick the first point..."))
  (setq jayudp2 (getpoint jayudp1 "\n Pick the second point..."))
  (command "-color" "1")
  (command "pline" jayudp1 "w" 0 0 jayudp2 "")
  (setq jayssobj (ssget "L"))
  (setq jayudp3 (getpoint jayudp2 "\n Pick the third point..."))
  (command "erase" jayssobj "")
  (command "pline" jayudp1 "w" 0 0 jayudp2 jayudp3 "")
  (setq jayssobj (ssget "L"))
  (setq jayudp4 (getpoint jayudp3 "\n Pick the last point..."))
  (command "erase" jayssobj "")
  (command "-color" "bylayer");revert color needs updated
  )
[/code]

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
color
« Reply #1 on: August 29, 2005, 11:32:18 AM »
Would something like this work for you?
Code: [Select]
 (setq usercolor (getvar "cecolor"))
  (setq jayudp1 (getpoint "\n Pick the first point..."))
  (setq jayudp2 (getpoint jayudp1 "\n Pick the second point..."))
  (setvar "cecolor" "1")
  (command "line" jayudp1 jayudp2 "")
  (setq jayssobj1 (entlast))
  (setq jayudp3 (getpoint jayudp2 "\n Pick the third point..."))
  (command "line" jayudp2 jayudp3 "")
  (setq jayssobj2 (entlast))
  (setq jayudp4 (getpoint jayudp3 "\n Pick the last point..."))
  (entdel jayssobj1)
  (entdel jayssobj2)
  (setvar "cecolor" usercolor) ;revert color needs updated
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
color
« Reply #2 on: August 29, 2005, 11:51:24 AM »
Here is something else to play with.
Code: [Select]
 (setq jayudp1 (getpoint "\n Pick the first point..."))
  (setq jayudp2 (getpoint jayudp1 "\n Pick the second point..."))
  (grdraw jayudp1 jayudp2 1 1)
  (setq jayudp3 (getpoint jayudp2 "\n Pick the third point..."))
  (grdraw jayudp2 jayudp3 1 1)
  (setq jayudp4 (getpoint jayudp3 "\n Pick the last point..."))
  (command "regen")
 
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jim Yadon

  • Guest
color
« Reply #3 on: August 29, 2005, 12:08:57 PM »
Thank you! I'll be toying with it shortly. I need to go heat my lunch up first.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
color
« Reply #4 on: August 29, 2005, 12:17:03 PM »
Additional food for thought:

Code: [Select]
(defun GetPoints ( / p i points )
    (cond
        (   (setq p (getpoint "\nPick first point: "))
            (setq points (list p) i -1)
            (while
                (setq p
                    (getpoint p
                        "\nPick next point / [Enter] to end: "
                    )
                )
                (grdraw p
                    (cadr (setq points (cons p points)))
                    -1
                    1
                )
            )
            (repeat (1- (length pts))
                (grdraw    
                    (nth (setq i (1+ i)) points)
                    (nth (1+ i) points)
                    -1
                    1
                )
            )
            (reverse points)
        )
    )
)

Here.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Jim Yadon

  • Guest
color
« Reply #5 on: August 29, 2005, 01:18:35 PM »
Now you're making my head hurt!  :oops:

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
color
« Reply #6 on: August 29, 2005, 01:22:21 PM »
Hey, i like it.
You could add number of points and color choice.

Code: [Select]
(defun GetPoints (#ofpts color / p i points pcnt)
  ;;  #ofpts  number of points allowed, nil = no limit
  ;;  color  is the color number
  (cond
    ((setq p (getpoint "\nPick first point: "))
     (setq points (list p)
           i      -1
           pcnt   0
     )
     (while
       (and (or (not #ofpts)
                (< (setq pcnt (1+ pcnt)) #ofpts))
            (setq p (getpoint p "\nPick next point / [Enter] to end: "))
       )
        (grdraw p (cadr (setq points (cons p points))) color 1)
     )
     (repeat (1- (length pts))
       (grdraw
         (nth (setq i (1+ i)) points)
         (nth (1+ i) points)
         color
         1
       )
     )
     (reverse points)
    )
  )
)


(getpoints 4 1) ; call the point routine
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
color
« Reply #7 on: August 29, 2005, 01:24:32 PM »
Dang, it's not supposed to do that!

If your run (GetPoints) it will prompt the user to select points, and as long as they don't press [enter] it stays in the "gathering" loop. Whilst collecting points it rubber bands between them so said user can see the points / perimeter they're establishing.  

Once the user terminates entry by hitting [enter] the points are returned to the caller, for eample, your program.

Try it out?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Jim Yadon

  • Guest
color
« Reply #8 on: August 29, 2005, 01:30:05 PM »
Quote from: MP
Dang, it's not supposed to do that!

If your run (GetPoints) it will prompt the user to select points, and as long as they don't press [enter] it stays in the "gathering" loop. Whilst collecting points it rubber bands between them so said user can see the points / perimeter they're establishing.  

Once the user terminates entry by hitting [enter] the points are returned to the caller, for eample, your program.

Try it out?


I have to get back to being productive before someone important comes along. I'll toy with it this evening and see if I can wrap my puny mind around it. Thanks M.

Jim Yadon

  • Guest
color
« Reply #9 on: August 30, 2005, 07:13:17 AM »
So, I am not sure where to start with passing the points along to a relative function. For that matter, this exercise is my first venture into anything remotely in depth in LISP for automating drawing. In the example below I've edited out the osnap and layer stuff and shown the meat of what I'm trying to do. The functions are also called upon by other routines and it's a work in progress.

And now for something completely LISP...

Code: [Select]
(defun c:hardwood_blocking()
  (jay-hardwood_blocking)
  )
(defun jay-hardwood_blocking()
  (jay-closedoor)
  (jay-userdef_4_points_random)
  (jay-4point_blocking_outline)
  (jay-4point_blocking_lines)
  (jay-opendoor)
  )

(defun jay-closedoor ()
  (setq ccmde (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq cosm (getvar "osmode"))
  (setvar "osmode" 0)
  (setq cl (getvar "clayer"))
  (setq usercolor (getvar "cecolor"))
  )

(defun jay-userdef_4_points_random()
  (setq jayudp1 (getpoint "\n Pick the first point..."))
  (setq jayudp2 (getpoint jayudp1 "\n Pick the second point..."))
  (grdraw jayudp1 jayudp2 1 1)
  (setq jayudp3 (getpoint jayudp2 "\n Pick the third point..."))
  (grdraw jayudp2 jayudp3 1 1)
  (setq jayudp4 (getpoint jayudp3 "\n Pick the last point..."))
  (command "regen")
  )

(defun jay-4point_blocking_outline()
  (setq jayp1 jayudp1
jayp2 jayudp2
jayp3 jayudp3
jayp4 jayudp4
)
  (jay-4point_object)
  (princ)
  )

(defun jay-4point_blocking_lines()
  (setq jayp1 jayudp1
jayp2 jayudp3
)
  (jay-2point_object)
  (setq jayp1 jayudp2
jayp2 jayudp4
)
  (jay-2point_object)
  )

(defun jay-opendoor ()
  (setvar "osmode" cosm)
  (setvar "cmdecho" ccmde)
  (setvar "clayer" cl)
  (setvar "cecolor" usercolor)
  )

(defun jay-4point_object()
  (command "pline" jayp1 "w" 0 0 jayp2 jayp3 jayp4 "cl")
  (setq jayssobj (ssget "L"))
  )

(defun jay-2point_object()
  (command "pline" jayp1 "w" 0 0 jayp2 "cl")
  (setq jayssobj (ssget "L"))
  )


Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
color
« Reply #10 on: August 30, 2005, 07:44:31 PM »
Hi Jim,
Since you say these functions are called from other routines as well this may be difficult to incorporate into your existing code, but I sure would look at using arguments in your functions to reduce the number of global variables flying around. Here's my rendition of your code, using just 1 global variable. That 1 is for the Selection set, since I'm not sure what you are doing with it.

I'm sure there are other ways of doing this, too, but since no one else has popped in I figured I'd throw in my $0.02
Code: [Select]

(defun c:hardwood_blocking()
  (setq jayssobj (ssadd))
  (jay-hardwood_blocking)
  )
(defun jay-hardwood_blocking(/ 4points)
  (jay-closedoor)
  (setq 4points (jay-userdef_4_points_random))
  (jay-4point-object 4points)
  (jay-blocking-lines 4points)
  (jay-opendoor)
  )

(defun jay-closedoor ()
  (setq ccmde (getvar "cmdecho"))
     (setvar "cmdecho" 0)
  (setq cosm (getvar "osmode"))
     (setvar "osmode" 0)
  (setq cl (getvar "clayer"))
  (setq usercolor (getvar "cecolor"))
  )

(defun jay-userdef_4_points_random(/ jayudp1 jayudp2 jayudp3 jayudp4)
  (setq jayudp1 (getpoint "\n Pick the first point..."))
  (setq jayudp2 (getpoint jayudp1 "\n Pick the second point..."))
  (grdraw jayudp1 jayudp2 1 1)
  (setq jayudp3 (getpoint jayudp2 "\n Pick the third point..."))
  (grdraw jayudp2 jayudp3 1 1)
  (setq jayudp4 (getpoint jayudp3 "\n Pick the last point..."))
  (command "redraw")
  (list jayudp1 jayudp2 jayudp3 jayudp4)
  )

(defun jay-blocking-lines (points)
  (command "pline" (nth 0 points) "w" 0 0 (nth 2 points) "")
  (ssadd (entlast) jayssobj)
  (command "pline" (nth 1 points) "w" 0 0 (nth 3 points) "")
  (ssadd (entlast) jayssobj)
  )

(defun jay-opendoor ()
  (setvar "osmode" cosm)
  (setvar "cmdecho" ccmde)
  (setvar "clayer" cl)
  (setvar "cecolor" usercolor)
  )

(defun jay-4point-object (points)
  (command "pline" (car points) "w" 0 0)
  (mapcar '(lambda (x)
    (command x)
    )
 (cdr points)
 )
  (command "cl")
  (ssadd (entlast) jayssobj)
  )


Also, in your 2point-object code you are drawing a 2 vertice pline....why do you close it? It seems to me this just adds an extra item for the display list to maintain while not doing anything for the actual drawing.

HTH,
Jeff

Jim Yadon

  • Guest
color
« Reply #11 on: August 31, 2005, 07:55:48 AM »
Thanks Jeff. Since most of my programming for ACAD up to this point has been data & xdata processing for MDB and working in VB/VBA I am venturing into new territory by working with LISP and automating my drawing work. I'll look this over after I get my submittal out today and let you know.