Author Topic: Simple code help please  (Read 5231 times)

0 Members and 1 Guest are viewing this topic.

Marti

  • Guest
Simple code help please
« on: April 06, 2004, 11:14:46 AM »
Hi all

I am very much a newbie at writing lisp and still find it hard to ‘see the wood for the trees’, so would be very grateful for any help.  I have an example to work out but can’t get started, the problem is:

To create an autolisp routine, which will prompt the user to input details, which will be used to create a polygon shape.  The shape should be drawn with the “Gas” linetype (which I have no problem producing but getting it into the routine?) and in colour red.  Within the shape the number (1) should be printed at text size 3.  This procedure must then be repeated ten times, with the linetype changing, the polygon dimensions incremented downwards from the original size and the colour changed from the previous.
The code should capture the default system variable at the beginning and then be reset at the end.

Any help would be most appreciated.

Marti

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Simple code help please
« Reply #1 on: April 06, 2004, 11:51:20 AM »
How about a dwg showing the shapes. Upload the dwg to
http://theswamp.org/lilly.pond/
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Simple code help please
« Reply #2 on: April 06, 2004, 12:06:03 PM »
Marti,
Most code projects start with pseudo code which is a detailed sequential explanation
of what is to take place. The more detailed you get the closet the code will come to
fulfilling your desired results.

You explanation so far is an over view with some details.
Can you be more specific and make sure the sequence of events is correct.

We all know that the code may change during the testing process due to unforseen
hurdles or undesired results. But you must start with a detailed plan of action.

Pseudo code questions:
prompt the user
What input details ? Points? How many?
Draw a polygon, Any restrictions on the shape, the size?
What is the color sequence?
What is the numeric sequence?
Where to place the text?
What portion of the routine to repeat?
Offset polygon how far?

Answer these questions & put them in the order you want processed
and that will be the beginning. I hope someone here can help you code it
as I am short of time this week.

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

Marti

  • Guest
Simple code help please
« Reply #3 on: April 20, 2004, 04:17:27 AM »
Thanks for the replys, as you can see i've managed to get started with a circle but would like help Please' with making it a polygon.  I've got the change colour to work but the line type bit is not working - Help Please!
Cab to answer some of your questions, there is no restriction on size, colour sequence etc, its is intended to be very simple code with at the writers discretion so long as the outlined criteria is followed.

I'd really appreciate a few mins of anyones time on this - thanks - Marti

(Defun C:CircleA (/ centre Rad colour texthei p1)
;Local variables are declared            

(setq centre (getpoint "\nPick centre of CircleA:"))      
;Request user to pick point for centre of circle

(setq rad(getdist centre "\nEnter radius value for CircleA: "))   
;Assign a value for Radius

(progn
; Ask the user what colour is required for the circle
         (setq colour (acad_colordlg 1))
         (if (= colour nil)
            (setq colour "1")
            (setq colour (itoa colour)) ; convert to string required for setvar function next
         )
; Now make the selected colour the current one
         (setvar "cecolor" colour)
)

;Ask the user what linetype is required
(progn
         (setq linetype acad linetypedlg 1))
         (if (= linetype nil)
            (setq linetype "1")
            (setq linetype (itoa linetype))
         )

(command "circle" centre Rad "")            
;Start of command function

(command ".text" centre 3 0 "1")


(Princ)                           
;Finnish cleanly

)

hendie

  • Guest
Simple code help please
« Reply #4 on: April 20, 2004, 06:02:51 AM »
Marti, as Cab has mentioned, we really need some pseudo code, and preferably a sample drawing to see what you are trying to do.
You mentioned a polygon at the beginning but your code shows a circle ~ the two objects are completely different types and would require separate code for each ~ the two are not interchangable.

you also mention the polygon dimensions incremented downwards which implies there must be a minimum dimension ofr the polygon to begin with. ~ Your text size is 3 ~ if the polygon is too small to begin with, all you will see is 10 text objects on top of each other, with some lines in there somewhere.

have a think about it, about how you would like to be prompted for the routine and how you think the routine should react. List all the prompts / commands etc and post you pseudo code and we'll see what we can do

Marti

  • Guest
Simple code help please
« Reply #5 on: April 20, 2004, 12:41:37 PM »
Thanks for the quick reply ……. Looks like I’ve caused a wee bit of confusion.  The circle code is just an example of what I’m trying to achieve, if run you will see the idea, but I want it to be a polygon but haven’t worked that out yet.  The minimum dimension of the polygon will be determined by the user, so if it is smaller than the text size it can be erased and done again – not a problem.

Prompts
Pick centre of polygon   ; could be anywhere on screen
Pick radius of polygon   ; as selected by rubber band or by numeric input at command line
Set the colour ; ask the user what colour is to be used for this polygon and set colour
Set the linetype ; ask the user what linetype is to be used for this polygon and set linetype
Draw the polygon
Have text number ‘1’  size 3 appear in the centre of each polygon without prompting

Create a loop enabling the command to be repeated as many times as the user requires allowing the colour and linetype to be changed as the user requires.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Simple code help please
« Reply #6 on: April 20, 2004, 09:55:57 PM »
You may want to look here for some code ideas.

http://theswamp.org/phpBB2/viewtopic.php?t=1230&highlight=bubble
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.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Simple code help please
« Reply #7 on: April 21, 2004, 12:19:44 PM »
Try this for the linetype problem.
Code: [Select]

(defun linetype-lst ( / lt lst)
  (setq lt (tblnext "ltype" T)
        lst (cons (cdr (assoc 2 lt)) lst)
        )
    (while
    (setq lt (tblnext "ltype"))
    (setq lst (cons (cdr (assoc 2 lt)) lst))
    )
  (if lst (reverse lst))
  )

(Defun C:CircleA (/ centre Rad colour texthei p1)
 ;Local variables are declared

  (setq centre (getpoint "\nPick centre of CircleA:"))
 ;Request user to pick point for centre of circle

  (setq rad (getdist centre "\nEnter radius value for CircleA: "))
 ;Assign a value for Radius

  (progn
 ; Ask the user what colour is required for the circle
    (setq colour (acad_colordlg 1))
    (if (= colour nil)
      (setq colour "1")
      (setq colour (itoa colour))
 ; convert to string required for setvar function next
      )
 ; Now make the selected colour the current one
    (setvar "cecolor" colour)
    )

 ;Ask the user what linetype is required
  (textscr)
  (setq lst (linetype-lst))
  (foreach x lst (princ (strcat "\n" x)))
  (setq lt (strcase (getstring "\nEnter a LINETYPE from the list: ")))
  (command "_linetype" "s" lt "")
 
  (command "circle" centre Rad "")
 ;Start of command function

  (command ".text" centre 3 0 "1")

  (graphscr)


  (Princ)
 ;Finnish cleanly

  )
TheSwamp.org  (serving the CAD community since 2003)

Anonymous

  • Guest
Simple code help please
« Reply #8 on: April 24, 2004, 12:39:55 PM »
A big thanks for the help Mark, I've changed your code from drawing a circle to a polygon and got the text bit in aswell.  All thats left to do is to get the code to repeat itself, after each polygon with text is drawn as many times as the user requires, i've spent hours with the 'loop' 'if' and 'repeat' commands but things are getting a bit foggy again - would appreciate any help in finnishing off - Many thanks

Marti
Code: [Select]

(defun linetype-lst ( / lt lst)
  (setq lt (tblnext "ltype" T)
        lst (cons (cdr (assoc 2 lt)) lst)
        )
    (while
    (setq lt (tblnext "ltype"))
    (setq lst (cons (cdr (assoc 2 lt)) lst))
    )
  (if lst (reverse lst))
  )

(Defun C:polygonC (/ A B C D)
 ;Local variables are declared

  (setq A (getpoint "\nEnter first point of polygonc:"))
  (setq B (getpoint "\nEnter next point: " A)
c B)


  (progn
 ; Ask the user what colour is required for the circle
    (setq colour (acad_colordlg 1))
    (if (= colour nil)
      (setq colour "1")
      (setq colour (itoa colour))
 ; convert to string required for setvar function next
      )
 ; Now make the selected colour the current one
    (setvar "cecolor" colour)
    )


 ;Ask the user what linetype is required
  (textscr)
  (setq lst (linetype-lst))
  (foreach x lst (princ (strcat "\n" x)))
  (setq lt (strcase (getstring "\nEnter a LINETYPE from the list: ")))
  (command "_linetype" "s" lt "")

 
   (command "_pline" A)
(while B
(command B)
(setq B (getpoint "\nEnter next point : " C)
C B)
)
(command "")
(setq D (getpoint "\nPick text position: "))


  (command ".text" D 3 0 "1")



  (graphscr)


  (Princ)
 ;Finnish cleanly

  )

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Simple code help please
« Reply #9 on: April 24, 2004, 01:19:19 PM »
I changed a couple things around, like the pline command.
Code: [Select]

(defun linetype-lst ( / lt lst)
  (setq lt (tblnext "ltype" T)
        lst (cons (cdr (assoc 2 lt)) lst)
        )
    (while
    (setq lt (tblnext "ltype"))
    (setq lst (cons (cdr (assoc 2 lt)) lst))
    )
  (if lst (reverse lst))
  )

(Defun C:polygonC (/ lst lt d)
 ;Local variables are declared

  (setq ans 1)

 ; start of loop
  (while (= ans 1)

    (progn
 ; Ask the user what colour is required for the circle
      (setq colour (acad_colordlg 1))
      (if (= colour nil)
        (setq colour "1")
        (setq colour (itoa colour))
 ; convert to string required for setvar function next
        )
 ; Now make the selected colour the current one
      (setvar "cecolor" colour)
      )


 ;Ask the user what linetype is required
    (textscr)
    (setq lst (linetype-lst))
    (foreach x lst (princ (strcat "\n" x)))
    (setq lt
           (strcase (getstring "\nEnter a LINETYPE from the list: "))
          )
    (command "_linetype" "s" lt "")

    (graphscr)

 ; start drawing polyline
    (command "_.pline")
    (while (= (logand (getvar "cmdactive") 1) 1)
      (command pause)
      )
    ;;while

    (setq D (getpoint "\nPick text position: "))

    (command ".text" D 3 0 "1")

    (setq ans (getreal "\nDo another? 1=yes 0=no: "))

    ) ; end of loop

  (Princ)
 ;Finnish cleanly

  )
TheSwamp.org  (serving the CAD community since 2003)

Marti

  • Guest
Simple code help please
« Reply #10 on: April 24, 2004, 01:54:29 PM »
Many thanks Mark - wish I could buy you a beer!  :D

Marti

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Simple code help please
« Reply #11 on: April 24, 2004, 02:02:37 PM »
Quote from: Marti
Many thanks Mark - wish I could buy you a beer!  :D

Marti

Next time I'm in your neck of the woods I'll let you. :D
TheSwamp.org  (serving the CAD community since 2003)