TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: AVCAD on September 17, 2004, 02:52:37 PM

Title: New Lisp Routine to challenge your Mind...
Post by: AVCAD on September 17, 2004, 02:52:37 PM
Well maybe not...but It is certanly challenging mine..

What I want is to have a set block...and have that block inserted multiple times across a given distance...

Sounds Easy but I cant figure it out.

So far I have been able to get the first point get the second point, get the angle (0,90,180,270) and insert the correct block for that angle...but I can only get it to insert once....actually I have no clue how to repeat the insert command...But if it is repeated it needs to change the postion of the block so tha the ends meet up...in this case the length of the block is 37.75

Here is my code so far...

Code: [Select]

(defun C:race ()
(setq P1 (getpoint "Start Point: "))
(setq P2 (getdist P1 "End Point: "))
(setq A (getangle P1 "Which Direction (0,90,180,270): "))
(if (= A 0) (command "INSERT" "G:/CHI-CUSTOMCAD/BLOCKS/TECHNOLOGY/TC/raceway-r.dwg" P1 "1" "1" "0"))
(if (= A pi) (command "INSERT" "G:/CHI-CUSTOMCAD/BLOCKS/TECHNOLOGY/TC/raceway-l.dwg" P1 "1" "1" "0"))
(if (= A (/ pi 2)) (command "INSERT" "G:/CHI-CUSTOMCAD/BLOCKS/TECHNOLOGY/TC/raceway-up.dwg" P1 "1" "1" "0"))
(if (= A (* 3 (/ pi 2))) (command "INSERT" "G:/CHI-CUSTOMCAD/BLOCKS/TECHNOLOGY/TC/raceway-dwn.dwg" P1 "1" "1" "0"))


IF there a better way of coding this I would be glad to listen. Also if you know of a way to have this work with any angle I would glad to listen to that too.
Title: New Lisp Routine to challenge your Mind...
Post by: CADaver on September 17, 2004, 02:58:25 PM
A couple of questions:

Is it a regular equidistant array?

Do you NEED 4 different blocks, or would one block with different rotation angles be sufficient?

Do you NEED multiple inserts, or would changing the X scale to the full length of the raceway be sufficient?
Title: New Lisp Routine to challenge your Mind...
Post by: TimSpangler on September 17, 2004, 03:23:32 PM
Code: [Select]

(repeat(fix(/(distance pt1 pt2)space))
(command "._circle" pt1 "12")
(setq pt1(polar pt1 0 space))
)


I think something like this will help
Title: New Lisp Routine to challenge your Mind...
Post by: AVCAD on September 17, 2004, 03:24:16 PM
Well first..

the block is a rectangle 37.75 long and about 5.5 wide. Half of the block is hatched with a solid.

IF copied (or array'ed) the distance would ne end to end so I guess it would be and equal distance each time.

I have it set up as 4 differant blocks right now because I dont know how to let it rotate the block by itself. I would like it to be 1 block with diferant rotations though.

I am interested in the last question. Could I just creat a really small block that have multiple hatchs in it and just scale the one block to the size of the raceway? This option I think would be great.
Title: New Lisp Routine to challenge your Mind...
Post by: CAB on September 17, 2004, 03:51:19 PM
Not exactly but it will do the job.

Code: [Select]
(defun c:race (/ p1 ang)
  (if (and
        (setq p1 (getpoint "\nPickInsert Point: "))
        (setq ang (getangle p1 "\nPick direction: "))
      )
    (progn
      (setq ang (* 180.0 (/ ang pi)))
      (command "INSERT" "G:/CHI-CUSTOMCAD/BLOCKS/TECHNOLOGY/TC/raceway-r.dwg"
               p1 "1" "" ang)
      (command "._copybase" p1 (entlast) "")
      (while t
        (command "._pasteclip" pause)
      )
    ) ; progn
  ) ; endif
  (princ)
) ; defun
Title: New Lisp Routine to challenge your Mind...
Post by: CAB on September 17, 2004, 03:52:47 PM
If the block already is in the drawing I use this one a lot.
Code: [Select]
(defun C:CopyR (/ EN OBJ pt)
  (prompt "Pick base point and object to copy:")
  (command "._copybase" pause pause "")
  (while t
    (command "._pasteclip" pause)
    (setq obj (entlast)); get last object
    (setq pt (cadr (grread t 1))); get insert point
    ;;  allow user to rotate
    (command "._rotate" Obj "" pt pause)
  )
  (princ)
)
(princ)
Title: New Lisp Routine to challenge your Mind...
Post by: AVCAD on September 17, 2004, 04:03:14 PM
well not exactly like you said....Is there away we can add a distance and insert the block over that set distance from the base point of the block to end of the block?
Title: New Lisp Routine to challenge your Mind...
Post by: CAB on September 17, 2004, 04:23:34 PM
Code: [Select]
(defun c:race (/ p1 ang ang2 cnt)
  (if (and
        (setq p1 (getpoint "\nPickInsert Point: "))
        (setq ang (getangle p1 "\nPick direction: "))
        (null(initget 7))
        (setq cnt (getint "\nEnter number of copies:"))
      )
    (progn
      (setq ang2 (* 180.0 (/ ang pi)))
      (command "INSERT" "G:/CHI-CUSTOMCAD/BLOCKS/TECHNOLOGY/TC/raceway-r.dwg"
               p1 "1" "" ang2)
      (command "._copybase" p1 (entlast) "")
      (repeat cnt
        (setq p1 (polar p1 ang 37.5))
        (command "._pasteclip" p1)
      )
    ) ; progn
  ) ; endif
  (princ)
) ; defun
Title: New Lisp Routine to challenge your Mind...
Post by: AVCAD on September 27, 2004, 10:21:43 AM
Well..I just got back from Cancun and thought I would check the status on this lisp routine.

This is more of what I wanted to accomplish but....in this routine it asks how many blocks t insert....

Is there away to make it just insert the blocks across that path...with out asking how many block to use?
Title: New Lisp Routine to challenge your Mind...
Post by: daron on September 27, 2004, 06:56:48 PM
Try measure or divide in your routine using the block feature.