Jump to content

More AutoCAD-like programs


KRBeckman

Recommended Posts

I'm trying to modify some of my lisps to make them look more like standard autocad commands and I'm wondering if anybody has some examples of how to do it.

 

What I'm trying to do is replace the 5 user text inputs with one menu of options that can be changed by first selecting what you want changed, then entering what you want the new value to be.

 

I'm not sure if this explains it very well, so I'll give an example...

 

I have a lisp that makes creating consecutive 3-d faces faster and easier by hidding neccessary edges and saving the verticies of the previous face so that a couple of them can be used for the following face (eliminates having to click on points twice, once for each face).

 

When I activate this lisp it first asks what type of face (first, middle, or last), then type of array (rectangular or circular), after that it asks if you want to switch back and forth between selecting the 3rd point before the 4th point and selecting the 4th point before the 3rd point (makes surfacing larger areas alot faster by eliminating alot of the zoom and panning), then which layer (current, temp, or name), finally whether or not you want to hide the inside edges.

 

What I would like to do is create a menu of options, kinda like the menu that comes up when you do a PEDIT:

 

Enter an option [Close/Join/Width/Edit ertex/Fit/Spline/Decurve/Ltype gen/Undo]:

 

But have it come up like this:

 

Enter and option [Face type/Array type/Oscillation/Layer/Hide Edges]:

 

And the user can change the settings he/she wants to, or just hit enter to continue the lisp.

 

I know how to make the prompt and strings, I just don't know how to loop back to the original prompt once a setting is changed.

 

Any help would be greatly appriciated.

Link to comment
Share on other sites

  • Replies 25
  • Created
  • Last Reply

Top Posters In This Topic

  • KRBeckman

    13

  • Lee Mac

    9

  • alanjt

    3

  • MSasu

    1

Top Posters In This Topic

Silly example:

 

(defun c:test (/ tot choice egg bac)
 (setq tot 0)
 
 (while
   (progn
     (initget "Checkout Eggs Bacon")
     (setq choice (getkword "\nWhat you wanna do? [Checkout/Eggs/Bacon] <Checkout> : "))

     (cond (  (or (eq "Checkout" choice)
                  (not choice))

              (princ (strcat "\nTotal = £" (itoa tot))) nil)

           (  (eq "Eggs" choice)

              (if (setq egg (getint "\nHow Many Eggs do you want? : "))
                (setq tot (+ tot (* 2 egg))))

              t)

           (t (if (setq bac (getint "\nHow Many rashers of Bacon? : "))
                (setq tot (+ tot (* 3 bac))))
            t))))

 (princ))

Link to comment
Share on other sites

lol, didn't mean you had to write it up, but I appriciated it... so what did you have for breakfast this morning?

Link to comment
Share on other sites

lol neither eggs or bacon actually :)

 

This may be a more intuitive approach to follow:

 

(defun c:test (/ tot choice egg bac ExitFlag)
 (setq tot 0)

 (while (not ExitFlag)

   (initget "Checkout Eggs Bacon")
   (setq choice (getkword "\nWhat you wanna do? [Checkout/Eggs/Bacon] <Checkout> : "))

   (cond (  (or (eq "Checkout" choice)
                (not choice))

            (princ (strcat "\nTotal = £" (itoa tot)))
            (setq ExitFlag t))

         (  (eq "Eggs" choice)

            (if (setq egg (getint "\nHow Many Eggs do you want? : "))
              (setq tot (+ tot (* 2 egg)))))

         (t (if (setq bac (getint "\nHow Many rashers of Bacon? : "))
              (setq tot (+ tot (* 3 bac)))))))

 (princ))

Link to comment
Share on other sites

I know in this case it works fine to do it the way you did, but would it make sense to change:

 

(t (if (setq bac (getint "\nHow Many rashers of Bacon? : "))
              (setq tot (+ tot (* 3 bac)))))))

 

To:

 

(  (eq "Bacon" choice)

            (if (setq bac (getint "\nHow Many rashers of Bacon? : "))
              (setq tot (+ tot (* 3 bac)))))))

 

I didn't know if this would be easier to understand if you came back to your program and needed to make a change a couple years down the road.

 

Also what does the "(t " this line do:

 

(t (if (setq bac (getint "\nHow Many rashers of Bacon? : "))

Link to comment
Share on other sites

I know in this case it works fine to do it the way you did, but would it make sense to change...

 

Perhaps, the responses are controlled by the initget function, so it makes no difference.

 

Also what does the "(t " this line do:

 

(t (if (setq bac (getint "\nHow Many rashers of Bacon? : "))

 

It ensures the last condition is met.

Link to comment
Share on other sites

I got a coupe more questions...

 

With this code:

 

(setq tpm (if
     (getkword
       (strcat "\nSetting to Change [Face type/Array type/"
        (if (= art "Rectangular") "Oscillation")
        "/Layer/Hide edges/<Continue>]: "))
     "Continue"))

 

I'm getting this in my commmand line:

 

Current Settings:

Face Type: First

Array Type: Rectangular

Third and Fourth Point Oscillation: Yes

Layer: 0

Hide Edges: Yes

Setting to Change: [Face type/Array type/Oscillation/Layer/Hide

edges/]

 

**My main problem is that the line for "Setting to Change..." is broken into 2 lines, is there a way to force this onto one line? I have plenty of room in my command line yet, so I don't believe its a margins thing. Anybody got any ideas??? ** -Disregard this question... when the user is prompted it shows up on one line, then changes...

 

The other, alot more minor thing, is that I would like to underline the "Current Settings" line of text in the command line. Is this possible?

Link to comment
Share on other sites

Nevermind found it.... needed "( (eq tpm "Cont")", not ( (eq tmp "Cont")"

 

Can someone please tell me why my loop won't end???

 

;  ___________________________________________________________________________________________  ;
;      i. Top Menu                                                                              ;
;  ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯  ;
     (while (not ext)
(princ "\n \nCurrent Settings: ")
(princ (strcat "\nFace Type: " fat))
(princ (strcat "\nArray Type: " art))
(if (= art "Rectangular")
  (princ (strcat "\nOscillation: " osc)))
(princ (strcat "\nLayer: "
        (if (= las "Temp") "Temp" (getvar 'clayer))))
(princ (strcat "\nHide Edges: " hed))
(initget "Face Array oScill layeR hidE Cont")
(setq tpm (cond
     ( (getkword
  (strcat "\nSetting to Change [Face type/Array type/oScillation/layeR/"
   "hide Edges/<Continue>]: ")))
     ("Cont")))

;  ___________________________________________________________________________________________  ;
;      i. Face Type                                                                             ;
;  ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯  ;
(cond
  ( (eq tpm "Face")
   (initget "First miDdle lAst")       
   (setq fat (cond         
        ( (getkword (strcat "\nFace Type? ["     
       (if (= fat "First" ) "<First>"  "First" )  
       "/"       
       (if (= fat "miDdle") "<miDdle>" "miDdle")  
       "/"       
       (if (= fat "lAst"  ) "<lAst>"   "lAst"  )  
       "]: ")))      
        (fat)))         
   )           


;  ___________________________________________________________________________________________  ;
;      ii. Array Type                                                                           ;
;  ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯  ;
  ( (eq tpm "Array")
   (initget "Rectangular Circular")       
   (setq art (cond         
        ( (getkword        
     (strcat "\nArray Type? ["      
      (if (= art "Rectangular") "<Rectangular>" "Rectangular") 
      "/"        
      (if (= art "Circular"   ) "<Circular>"    "Circular"   ) 
      "]: ")))       
        (art)))         
   )

;  ___________________________________________________________________________________________  ;
;      iii. Third and Fourth Point Selection Oscillation                                        ;
;  ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯  ;
  ( (eq tpm "oScill")
    (if (= art "Circular")
      (progn
 (initget "Yes No")
 (setq cat (cond
      ((getkword (strcat "\nArray type is not currenty set to "
           "rectangular, change to circular? [<Yes>/No]: "
           )))
      ("Yes")))
 (if (= cat "Yes")
   (setq osc "Yes"
  art "Rectangular")
   )))
   )


;  ___________________________________________________________________________________________  ;
;      iii. Layer selection                                                                     ;
;  ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯  ;
  ( (eq tpm "layeR")
   (initget "Current Temp")         
   (setq las (cond          
        ( (getkword (strcat "\nLayer? ["      
       (if (= las "Current") "<Current>" "Current")  
       "/"       
       (if (= las "Temp"   ) "<Temp>"    "Temp"   )  
       "]: ")))      
        (las)))         

   )

;  ___________________________________________________________________________________________  ;
;      iv. Hide edges                                                                           ;
;  ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯  ;
  ( (eq tpm "hidE")
   (initget "Yes No")          
   (setq hed (cond         
        ( (getkword (strcat "\nHide Inside Edges? [<Yes>/No]: ")))  
        (hed)))         
   )

;  ___________________________________________________________________________________________  ;
;      iv. End Loop (Continue)                                                                  ;
;  ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯  ;
  ( (eq tmp "Cont")
   (setq ext 1)
   )

  )           
)           
   

 

I'm guessing its going to be a little detail, but I can't find it.

Link to comment
Share on other sites

LoL

Lee, you were talking about being immature...

 

 (princ (strcat "\nFace Type: " [color=Red]fa[/color]t))
(princ (strcat "\nArray Type: " a[color=Red]rt[/color]))

 

[i play a lot of boggle.]

Link to comment
Share on other sites

I keep coming up with more questions.... but how would I change a prompt to accept a mouse click in addition to a text input.

 

And then if it was a mouse click, how would use the coordinates of that point and apply it to a variable?

 

Not sure if this makes 100% sense, so for an example look at the autocad arc command, after you initiate the are command you have an option you can activate by hitting the "c" key, or you can click and it accepts that as the first point of the arc.

Link to comment
Share on other sites

I did, and I understand that if you use 128 as the bit-code for the initget function that it will allow you to inputer keyboard entries into a getpoint function, but I don't see how that combines the getkword to make sure the user is only entering either the options you give them, or a point.

 

Sorry if I'm being thick, I'm just not very good at figuring this kind of stuff out fromt the help files.

Link to comment
Share on other sites

How about this part :)

 

The functions that honor keywords are getint, getreal, getdist, getangle, getorient, getpoint, getcorner, getkword, entsel, nentsel, and nentselp. The getstring function is the only user-input function that does not honor keywords.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...