Author Topic: Vlisp help...  (Read 3756 times)

0 Members and 1 Guest are viewing this topic.

Water Bear

  • Guest
Vlisp help...
« on: May 19, 2004, 10:14:53 AM »
I did some "surgery" on this app to get it read from an externa file..the problem is that if I run it, my other routines don't work properly. That is. as long as it is resident. I not very familiar with the VL commands, so I'd like you guys who are, to see if there is something in here that shouldn't be.
Code: [Select]

;;set up default rotation angle
(if (= rot nil) (setq rot 0) )

;;define the function and declare all local variables
(defun WF-Steel (/ ptlist  oldsnap oldecho oldblip acaddoc util
  mspace  names   sizes   dcl_id  siza   userclick
  dlist   H   B   T1   T2   R1
  IP   IPA   P1   ptlisp  tmp   myobj
  fname   fn   pts   size   file   fp
  item   data   maxs   count   chrct   numb
  )
  ;;load VL functions
  (vl-load-com)

  ;;obtain reference to the Active Document
  (setq acaddoc (vla-get-activeDocument (vlax-get-acad-object)))

  ;;obtain reference to Utilities
  (setq util (vla-get-utility acaddoc))

  ;;obtain reference to Model Space
  (setq mspace (vla-get-modelSpace acaddoc))

  ;;store system variables
  (setq oldsnap (vla-getvariable acaddoc "OSMODE")
oldecho (vla-getvariable acaddoc "CMDECHO")
oldblip (vla-getvariable acaddoc "BLIPMODE")
) ;setq

  ;;switch off system variables
  (vla-setvariable acaddoc "CMDECHO" 0)
  (vla-setvariable acaddoc "BLIPMODE" 0)

  ;;create list of steel sections for the list box
  (setq names '("w36x300"
"w36x280"
"w36x260"
"w36x245"
)
)


  ;;construct the dialog
  (create_dialog)

  ;;load the dialog
  (setq dcl_id (load_dialog fname))
  (if (not (new_dialog "ubeam" dcl_id))
    (exit)
    )

  ;;setup the list box
  (start_list "selections")
  (mapcar 'add_list names)
  (end_list)

  ;;default rotation angle
  (set_tile "rot" (rtos rot 2 1))

  ;;setup the Cancel button
  (action_tile
    "cancel"
    "(done_dialog) (setq userclick nil)"
    )

  ;;setup the OK button
  (action_tile
    "accept"
    (strcat
      "(progn (setq siza (atof (get_tile \"selections\")))
                   (setq rot (atof (get_tile \"rot\")))"
      "(done_dialog) (setq userclick T))"
      )
    )

  ;;display the dialog
  (start_dialog)

  ;;unload the dialog
  (unload_dialog dcl_id)

  ;;delete the temp DCL file
  (vl-file-delete fname)

  ;;if the OK button was selected
  (if userclick

    ;;do the following
    (progn

      ;;retrieve the steel section values

      (setq dlist (nth (fix siza) names))
      (setq size  (strcat "*" dlist)
   file  (findfile "steel tables.dat")
   fp  (open file "r")
   item  (read-line fp)
   dlist nil
   ) ;setq
      (while item
(if (= item size)
 (setq data (read-line fp)
item nil
) ;setq
 (setq item (read-line fp))
 ) ;if
) ;while
;;;*Format List
      (if data
(progn
 (setq maxs  (strlen data)
count 1
chrct 1
) ;setq
 (while (< count maxs)
   (if (/= "," (substr data count 1))
     (setq chrct (1+ chrct))
     (setq numb  (atof (substr data (1+ (- count chrct)) chrct))
   dlist (append dlist (list numb))
   chrct 1
   ) ;setq
     ) ;if
   (setq count (1+ count))
   ) ;while
 (setq numb  (atof (substr data (1+ (- count chrct))))
dlist (append dlist (list numb))
) ;setq
 ) ;progn
) ;if data
      (close fp)

      ;;place them into variables
      (mapcar 'set '(H B T1 T2 R1) dlist)

      ;;switch on the intersection snap
      (vla-setvariable acaddoc "OSMODE" 32)

      ;;get the insertion point
      (setq IP (vla-getpoint util nil "\nInsertion Point : "))

      ;;switch off the snaps  
      (vla-setvariable acaddoc "OSMODE" 0)

      ;;calculate the points and store them in a list
      (setq pts (list
 (setq P1 (vla-polarpoint util IP 0 (/ T2 2)))
 (setq P1 (vla-polarpoint
    util
    P1
    (DTR 90.0)
    (/ (- H (+ T1 T1 R1 R1)) 2)
    )
)
 (setq P1 (vla-polarpoint
    util
    P1
    (DTR 45.0)
    (sqrt (* R1 R1 2.0))
    )
)
 (setq P1 (vla-polarpoint
    util
    P1
    0
    (/ (- B (+ T2 R1 R1)) 2)
    )
)
 (setq P1 (vla-polarpoint util P1 (DTR 90.0) T1))
 (setq P1 (vla-polarpoint util P1 (DTR 180.0) B))
 (setq P1 (vla-polarpoint util P1 (DTR 270.0) T1))
 (setq P1 (vla-polarpoint
    util
    P1
    0
    (/ (- B (+ T2 R1 R1)) 2)
    )
)
 (setq P1 (vla-polarpoint
    util
    P1
    (DTR 315.0)
    (sqrt (* R1 R1 2.0))
    )
)
 (setq P1 (vla-polarpoint
    util
    P1
    (DTR 270.0)
    (- H (+ T1 T1 R1 R1))
    )
)
 (setq P1 (vla-polarpoint
    util
    P1
    (DTR 225.0)
    (sqrt (* R1 R1 2.0))
    )
)
 (setq P1 (vla-polarpoint
    util
    P1
    (DTR 180.0)
    (/ (- B (+ T2 R1 R1)) 2)
    )
)
 (setq P1 (vla-polarpoint util P1 (DTR 270.0) T1))
 (setq P1 (vla-polarpoint util P1 0 B))
 (setq P1 (vla-polarpoint util P1 (DTR 90.0) T1))
 (setq P1 (vla-polarpoint
    util
    P1
    (DTR 180.0)
    (/ (- B (+ T2 R1 R1)) 2)
    )
)
 (setq P1 (vla-polarpoint
    util
    P1
    (DTR 135.0)
    (sqrt (* R1 R1 2.0))
    )
)
 (setq P1 (vla-polarpoint util IP 0 (/ T2 2)))
 )
   ) ;setq

      ;;extract only the X and Y values of each point list
      (mapcar

'(lambda (pt)

  ;;convert to lists
  (setq pt (vlax-safearray->list (variant-value pt)))

  ;;X and Y values only
  (setq ptlist (cons (list (car pt) (cadr pt)) ptlist))

  ) ;lambda

pts

) ;mapcar

      ;;break the point list up into elements
      (setq ptlist (apply 'append ptlist))

      ;;create a safearray to store the elements
      (setq tmp (vlax-make-safearray
 vlax-vbDouble
 (cons 0 (- (vl-list-length ptlist) 1))
 )
   )

      ;;fill the safearray
      (vlax-safearray-fill tmp ptlist)

      ;;draw the steel section
      (setq myobj (vla-addLightweightPolyline mspace tmp))

      ;;radius the corners
      (vla-setbulge myobj 1 0.4142)
      (vla-setbulge myobj 7 0.4142)
      (vla-setbulge myobj 9 0.4142)
      (vla-setbulge myobj 15 0.4142)

      ;;rotate the object
      (vla-rotate myobj ip (dtr rot))

      ) ;progn

    ) ;if

  ;;reset system variables
  (vla-setvariable acaddoc "OSMODE" oldsnap)
  (vla-setvariable acaddoc "CMDECHO" oldecho)
  (vla-setvariable acaddoc "BLIPMODE" oldblip)

  ;;release all objects
  (vlax-release-object mspace)
  (vlax-release-object util)
  (vlax-release-object acaddoc)

;finish clean
  (princ)

  ) ;defun

;;;--------------------------
(defun create_dialog ()

  ;;create a temp DCL file
  (setq fname (vl-filename-mktemp "dcl.dcl"))

  ;;open it to write
  (setq fn (open fname "w"))

  ;;write the dialog coding
  (write-line
    "ubeam : dialog {
     label = \"Wide Flange Steel\";
     : list_box {
        label = \"Choose Section :\";
        key = \"selections\";
        allow_accept = true;
        height = 8;
     }
     : edit_box {
       label = \"Rotation Angle :\";
       key = \"rot\";
       edit_limit = 4;
       edit_width = 4;
      }
      spacer;  
     ok_cancel ;
     :text_part {
         label = \"Designed\";
      }
     
     }"
    fn
    )

  ;;close the temp DCL file
  (close fn)

  ) ;defun
;;;------------------------------

;convert degrees to radians

(defun DTR (a)
  (* pi (/ a 180))

  ) ;defun

;;;---------------------------------

;;load clean
(princ)
The data source file is called steel tables.dat
Code: [Select]
;;;wide flange shapes
;;;depth,fwidth,fthick,webthick,radius
*w36x300
36.750,16.625,1.6875,0.9375,0.95
*w36x280
36.500,16.625,1.5625,0.8750,0.95
*w36x260
36.250,16.500,1.4375,0.8125,0.95
*w36x245
36.125,16.500,1.3750,0.8125,0.95

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Vlisp help...
« Reply #1 on: May 19, 2004, 11:58:06 AM »
It works good for me! I tried several of my own apps and had no problems. What are the apps that don't work?
TheSwamp.org  (serving the CAD community since 2003)

Water Bear

  • Guest
Vlisp help...
« Reply #2 on: May 19, 2004, 11:18:58 PM »
Thanks for taking a look Mark. I went though all the routines and found the culprit! This was defined in my project as a standard subroutine
Code: [Select]
;;;define degrees to radians function
(defun dtr (x)
  (* pi (/ x 180.0)) ;divide the angle by 180 then
;multiply the result by the constant PI
  ) ;end of function


Notice that it is redefined in the the previous post...that was the cause!
Code: [Select]
              ;convert degrees to radians

(defun DTR (a)
  (* pi (/ a 180))

  )               ;defun
I remmed it out and then all worked well...though, quite honestly I don't really see the difference except for the REAL, does it make sense to you?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Vlisp help...
« Reply #3 on: May 20, 2004, 12:22:24 AM »
Does this help ??
From the Autolisp Reference help file
Operators -> /[divide]
Quote

Divides the first number by the product of the remaining numbers and returns the quotient

(/ [number number] ...)

Arguments

number

A number.

Return Values

The result of the division. If you supply more than two number arguments, this function divides the first number by the product of the second through the last numbers, and returns the final quotient. If you supply one number argument, this function returns the result of dividing it by one; it returns the number. Supplying no arguments returns 0.

Examples

(/ 100 2)                 returns  50
(/ 100 2.0)               returns  50.0
(/ 100 20.0 2)            returns  2.5
(/ 100 20 2)              returns  2
(/ 4)                     returns  4



The same rules apply for addition, subtraction and multiplication.
.. in short  :: Result Variable type is automatically changed to match the more complex of the arguments passed
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

DEVITG

  • Bull Frog
  • Posts: 480
Vlisp help...
« Reply #4 on: May 20, 2004, 11:48:48 PM »
When I use angles at fixed values I use this

Code: [Select]

(SETQ p (* 4.0 (atan 1 1)))  ; a PI definition
(SETQ P2 (/ P 2.0))  ; 90 DEGREE
(SETQ P4 (/ P 4.0))  ;45 DEGREE
(SETQ P30 (/ P 6.0))  ; 30 DEGREE
(SETQ P60 (/ P 3.0))  ;60 DEGREE
(setq p120 (* 2 p60))
(setq p180 p)  ;180 degre
(Setq p270 (* 3 p2))  ;270 degree
;;******************************************************  


I define P as ( * 4 (atan 1 1)) just to keep it in my RAM memory , I know that lisp as it's own PI definition
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Water Bear

  • Guest
Vlisp help...
« Reply #5 on: May 21, 2004, 08:41:22 AM »
Does anyone know of a book for Vlisp terms similiar to the one "The Autocad Programming and Customizing Quick Reference - by Grabowski" ? I find it comforting to have a reference right at my fingertips...

DEVITG

  • Bull Frog
  • Posts: 480
my first step on LISP
« Reply #6 on: May 21, 2004, 10:08:53 AM »
here you can find it

http://courses.home.att.net/autolisp/

It is the most comprensive text I found
I use this quick reference guide

http://courses.home.att.net/autolisp/acatalog.htm
Location @ Córdoba Argentina Using ACAD 2019  at Window 10