Exchange Forum > Dcl Dialogs
Pole Shaft program help
Page 1 of 2
1 2
Pole Shaft program help

#1

Justin
Join Date:
09-24-2007
An Engineer friend that I work with has ask me if I could write an AutoLISP program to draw an elevation view of a pole shaft. I have modified the dialog that Trevor suggested in one of the threads and came up with this preliminary lisp file and dialog file. The math seams a bit complicated, but my friend assures me that we can work through it together. Here is what I have developed so far. I'd appreciate any suggestions on how I should proceed to make the program better. Keep in mind that this is a work in progress until finished. I appreciate all your help.
Thanks,
Justin
 
Code:
//PoleShaft.dcl
PoleShaft : dialog {
  label = "Pole Shaft";
  spacer;
  : row { fixed_width = true;
    : column { width = 14.5; spacer;
      : text { key = "Text1"; }
    }
    : popup_list { width = 13;
      key = "List1";
    }
  }
  : row { fixed_width = true;
    : column { width = 14.5; spacer;
      : text { key = "Text2"; }
    }
    : edit_box { edit_width = 11;
      key = "Edit2";
    }
  }
  : row { fixed_width = true;
    : column { width = 14.5; spacer;
      : text { key = "Text3"; }
    }
    : edit_box { edit_width = 11;
      key = "Edit3";
    }
  }
  : row { fixed_width = true;
    : column { width = 14.5; spacer;
      : text { key = "Text4"; }
    }
    : edit_box { edit_width = 11;
      key = "Edit4";
    }
  }
  : row { fixed_width = true;
    : column { width = 14.5; spacer;
      : text { key = "Text5"; }
    }
    : popup_list { width = 13;
      key = "List5";
    }
  }
  spacer;
  : row {
    : column {
      : ok_button { width = 11;
        alignment = right;
      }
    }
    : column {
      : cancel_button { width = 11;
        alignment = left;
      }
    }
  }
}
Code:
;PoleShaft.lsp
(defun c:PoleShaft (/ )
  (if (not *List1) (setq *List1 "6"))
  (if (not *Edit2) (setq *Edit2 "8"))
  (if (not *Edit3) (setq *Edit3 "10"))
  (if (not *Edit4) (setq *Edit4 "100"))
  (if (not *List5) (setq *List5 "Flat"))
  (setq PopList1 (list "6" "8" "10" "12" "14" "16" "18"))
  (setq PopList5 (list "Flat" "Edge"))
  (setq Dcl_ID (load_dialog "PoleShaft.dcl"))
  (new_dialog "PoleShaft" Dcl_ID)
  (set_tile "Text1" "Number of Sides")
  (start_list "List1")(mapcar 'add_list PopList1)(end_list)
  (set_tile "List1" (itoa (- (length PopList1) (length (member *List1 PopList1)))))
  (set_tile "Text2" "Top Diameter")
  (set_tile "Edit2" *Edit2)
  (set_tile "Text3" "Bottom Diameter")
  (set_tile "Edit3" *Edit3)
  (set_tile "Text4" "Pole Height")
  (set_tile "Edit4" *Edit4)
  (set_tile "Text5" "Front View")
  (start_list "List5")(mapcar 'add_list PopList5)(end_list)
  (set_tile "List5" (itoa (- (length PopList5) (length (member *List5 PopList5)))))
  (action_tile "List1" "(setq *List1 (nth (atoi (get_tile \"List1\")) PopList1))")
  (action_tile "Edit2" "(setq *Edit2 (get_tile \"Edit2\"))")
  (action_tile "Edit3" "(setq *Edit3 (get_tile \"Edit3\"))")
  (action_tile "Edit4" "(setq *Edit4 (get_tile \"Edit4\"))")
  (action_tile "List5" "(setq *List5 (nth (atoi (get_tile \"List5\")) PopList5))")
  (action_tile "accept" "(done_dialog 1)")
  (action_tile "cancel" "(done_dialog 0)")
  (setq Return (start_dialog))
  (unload_dialog Dcl_ID)
  (if (= Return 0) (exit))
  (if (or (<= (atof *Edit2) 0)(<= (atof *Edit3) 0)(<= (atof *Edit4) 0))
    (progn
      (alert "The Top and Bottom Diameter and\nPole Height must be greater than 0.")
      (c:PoleShaft)
    )
  )
  (princ "\nNumber of Sides = ")(princ *List1)
  (princ "\nTop Diameter = ")(princ *Edit2)
  (princ "\nBottom Diameter = ")(princ *Edit3)
  (princ "\nPole Height = ")(princ *Edit4)
  (princ "\nFront View = ")(princ *List5)
  (textscr);That's what I've got so far.
  (princ)
)



Attachments  PoleShaft.gif  
Pole Shaft program help

#2

J Briggs
Join Date:
07-25-2007
Justin,
You’re off to a good start. The only thing I would suggest is to allow the dimensions to be entered in architectural or real numbers. You might also want to update the dimensions in the edit_box tiles to real numbers to be compatible with AutoCAD users using metric standards as well as those using architectural standards.
So, how soon do we get to test it out?
Pole Shaft program help

#3

Justin
Join Date:
09-24-2007
I only get to work on my programs once in a while. So I'm not sure when it'll be ready for testing. Does anyone have an example of how to update these edit boxes?
Thanks for your help and advice.
Justin
Pole Shaft program help

#4

Quick Silver
Join Date:
11-01-2007
Justin,
You might be able to use a function to convert the value from the edit_box into a string real number and just update the edit_box tile with the new value. There was a similar discussion in the following thread.
..\Forum2\F2T28P1.htm#4
Here is a slight modification to the one I previously posted. It converts a string number in any format into a string of the real number.
 
Code:
(defun realstring (str / dimzin)
 (setq dimzin (getvar "dimzin"))(setvar "dimzin" 8)
 (setq str
  (cond
   ((distof str 1)(rtos (distof str 1) 2 8))
   ((distof str 2)(rtos (distof str 2) 2 8))
   ((distof str 3)(rtos (distof str 3) 2 8))
   ((distof str 4)(rtos (distof str 4) 2 8))
   ((distof str 5)(rtos (distof str 5) 2 8))
   (t "")
  )
 )
 (setvar "dimzin" dimzin)
 str
)
Pole Shaft program help

#5

Trevor
Join Date:
07-29-2007
Quote:
I have modified the dialog that Trevor suggested in one of the threads and came up with this preliminary lisp file
and dialog file.
Thanks for giving me some of the credit, but I think most of it should go to Bennett and J Briggs. They've help me out a lot.
You're most likely going to need sub-functions for updating the tiles and checking the values. I think Bennett suggested this somewhere, when the commands become too long to add to the end of an action_tile.
I noticed you used an early version of mine to setq a variable to an item in a popup_list. I've found a shorter version that you might want to use instead.
Code:
;Early version
(action_tile "List1" "(setq *List1 (nth (atoi (get_tile \"List1\")) PopList1))")
;New version
(action_tile "List1" "(setq *List1 (nth (atoi $value) PopList1))")
Best of luck with your program, and I'm looking forward to checking it out when you get it finished.
Trevor
Pole Shaft program help

#6

Bennett
Join Date:
07-26-2007
Quote:
Does anyone have an example of how to update these edit boxes? 
You can combine the realstring function that Quick Silver submitted into a sub-function to update your edit boxes.
Here's the basics of what you'll need. You might want to include error checking for 0 and negative values.
Bennett
Code:
;In the action_tile section:
(action_tile "Edit2" "(Update_Dim)");etc.
 
;You can use the same sub-function for all your edit boxes,
;by putting the $key, tile name, in a cond statement:
(defun Update_Dim ()
  (cond
    ((= $key "Edit2")
      (setq *Edit2 (realstring $value))
      (set_tile "Edit2" *Edit2)
    )
    ;etc.
  )
)
Pole Shaft program help

#7

Justin
Join Date:
09-24-2007
I appreciate all your help and suggestions. I had a little time to work my program this week and here's the latest. I'll start working on the math and the draw part next week, but I just wanted to keep you up to date. I am very happy the way the edit boxes allow you to enter in the dimensions in different ways. We're used to having a calculator handy to convert the dimensions for the dialog into inches. Quick Silver, thanks for the code for RealString. It works great!
Justin
Code:
(defun c:PoleShaft (/ Dcl_ID PopList1 PopList5 Return UpdateDim)
  (defun UpdateDim (/ StrNum)
    (cond
      ((= $key "Edit2")
        (setq StrNum (RealString $value))
        (if (> (atof StrNum) 0)
          (progn
            (setq *Edit2 StrNum)
            (set_tile "Edit2" *Edit2)
            (if (= $reason 1) (mode_tile "Edit3" 2))
          )
          (progn
            (alert "The value for Top Diameter\nmust be greater than 0!")
            (set_tile "Edit2" *Edit2)
            (mode_tile "Edit2" 2)
          )
        )
      )
      ((= $key "Edit3")
        (setq StrNum (RealString $value))
        (if (> (atof StrNum) 0)
          (progn
            (setq *Edit3 StrNum)
            (set_tile "Edit3" *Edit3)
            (if (= $reason 1) (mode_tile "Edit4" 2))
          )
          (progn
            (alert "The value for Bottom Diameter\nmust be greater than 0!")
            (set_tile "Edit3" *Edit3)
            (mode_tile "Edit3" 2)
          )
        )
      )
      ((= $key "Edit4")
        (setq StrNum (RealString $value))
        (if (> (atof StrNum) 0)
          (progn
            (setq *Edit4 StrNum)
            (set_tile "Edit4" *Edit4)
            (if (= $reason 1) (mode_tile "List5" 2))
          )
          (progn
            (alert "The value for Pole Height\nmust be greater than 0!")
            (set_tile "Edit4" *Edit4)
            (mode_tile "Edit4" 2)
          )
        )
      )
    )
  )
  (if (not *List1) (setq *List1 "6"))
  (if (not *Edit2) (setq *Edit2 "8"))
  (if (not *Edit3) (setq *Edit3 "10"))
  (if (not *Edit4) (setq *Edit4 "100"))
  (if (not *List5) (setq *List5 "Flat"))
  (setq PopList1 (list "6" "8" "10" "12" "14" "16" "18"))
  (setq PopList5 (list "Flat" "Edge"))
  (setq Dcl_ID (load_dialog "PoleShaft.dcl"))
  (new_dialog "PoleShaft" Dcl_ID)
  (set_tile "Text1" "Number of Sides")
  (start_list "List1")(mapcar 'add_list PopList1)(end_list)
  (set_tile "List1" (itoa (- (length PopList1) (length (member *List1 PopList1)))))
  (set_tile "Text2" "Top Diameter")
  (set_tile "Edit2" *Edit2)
  (set_tile "Text3" "Bottom Diameter")
  (set_tile "Edit3" *Edit3)
  (set_tile "Text4" "Pole Height")
  (set_tile "Edit4" *Edit4)
  (set_tile "Text5" "Front View")
  (start_list "List5")(mapcar 'add_list PopList5)(end_list)
  (set_tile "List5" (itoa (- (length PopList5) (length (member *List5 PopList5)))))
  (action_tile "List1" "(setq *List1 (nth (atoi $value) PopList1))")
  (action_tile "Edit2" "(UpdateDim)")
  (action_tile "Edit3" "(UpdateDim)")
  (action_tile "Edit4" "(UpdateDim)")
  (action_tile "List5" "(setq *List5 (nth (atoi $value) PopList5))")
  (setq Return (start_dialog))
  (unload_dialog Dcl_ID)
  (if (= Return 0) (exit))
  (princ "\nNumber of Sides = ")(princ *List1)
  (princ "\nTop Diameter = ")(princ *Edit2)
  (princ "\nBottom Diameter = ")(princ *Edit3)
  (princ "\nPole Height = ")(princ *Edit4)
  (princ "\nFront View = ")(princ *List5)
  (textscr);That's what I've got so far.
  (princ)
)
(defun RealString (StrNum / DimZin)
  (setq DimZin (getvar "dimzin"))(setvar "dimzin" 8)
  (setq StrNum
    (cond
      ((distof StrNum 1)(rtos (distof StrNum 1) 2 8))
      ((distof StrNum 2)(rtos (distof StrNum 2) 2 8))
      ((distof StrNum 3)(rtos (distof StrNum 3) 2 8))
      ((distof StrNum 4)(rtos (distof StrNum 4) 2 8))
      ((distof StrNum 5)(rtos (distof StrNum 5) 2 8))
      (t "")
    )
  )
  (setvar "dimzin" DimZin)
  StrNum
)
Pole Shaft program help

#8

Justin
Join Date:
09-24-2007
I have been testing my PoleShaft program for a few days now. It draws the elevation view of pole shafts using your input information. You can enter the dimension values in feet and inches or as real numbers for metric users. The math wasn’t so hard after all.
Give it a try and let me know what you think.
Justin
 
Note: The dcl file is the same one as in the first post.



Attachments  PoleShaft.lsp    PoleShaft.dcl    PoleShaftDwg.gif  
Pole Shaft program help

#9

J Briggs
Join Date:
07-25-2007
Justin,
I just ran it and it works like a charm. I also tested entering architectural and real numbers in the edit boxes. This should be a great time saver at your work.
Pole Shaft program help

#10

Trevor
Join Date:
07-29-2007
I helped a friend load your program on his computer. He's not into programming so he couldn't understand that he also needed to copy and paste the code from your PoleShaft.dcl into a text file and save it into the folder with his AutoLISP routines. I got it working for him, and he thinks it's pretty cool. It sure beats drawing it up the conventional way.
Trevor
Page 1 of 2
1 2