Author Topic: Question about naming LISP files & defun  (Read 3870 times)

0 Members and 1 Guest are viewing this topic.

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Question about naming LISP files & defun
« on: March 10, 2004, 11:32:19 AM »
I'm making a series of hatching LISP's that will set the current layer to that of the hatch it creates, set the appropriate hatch properties, then lets you select the points for the hatch, and then returns layer to previous, and hatch settings to previous...

Probably didn't need that information for my question, but as some might recall, I'm new to this and I feel like I'm bragging, when in actuality I know it's pretty simple stuff...

ANYWAYS!!!  Here is a sample of a siding hatch routine (as far as naming goes):

Hatch_EL_Siding_4in.lsp....
(defun c:Siding4 ()...
*layer creation of layer named* EL-HATCH-SIDING

Hatch_EL_Brick.lsp....
(defun c:Brick ()...
*layer creation of layer named* EL-HATCH-BRICK

Hatch_PL_Wall_Standard.lsp....
(defun c:WallHatchStandard ()...
*layer creation of layer named* PL-HATCH-WALL

Do these namings look about right?  I'm trying to get a standard way to name and defun each lisp.  We are currently changing our layers to PL-.... and EL.... for Plan and Elevation.  Is there anything that should be changed, or does it look ok?  The Wall Hatch defun doesn't follow the rest, so that's kind of what I'm concerned about.

And all the routines are called thru buttons and menus, so long defuns don't bother me, I won't be typing them in.

Sorry so long...

 :twisted:

One of the routines if anyone wants to critique:
Code: [Select]

;;***********************************************
;;           Hatch_EL_Siding_4in.lsp            *
;;          Created by Dominic Cesare           *
;;                 02.27.04                     *
;;             Revised: 03.03.04                *
;;***********************************************

;;**********************
;;*  Start of Routine  *
;;**********************

;informs user how to run lisp
(prompt "\nType Siding4 to run.....")

;define function
(defun c:Siding4 ()
  ;getting current vars
  (setq clay (getvar "clayer"))
  (setq echo (getvar "cmdecho"))
  (setq oldhpname (getvar "hpname"))
  (setq oldhpspace (getvar "hpspace"))
  (setq oldhpang (getvar "hpang"))
  ;turning off echo
  (setvar "cmdecho" 0)
  ;creating layer BRICK-EL
  (command "-layer" "m" "EL-HATCH-SIDING" "c" "251" "" "")
  ;setting hatch vars
  (setvar "hpname" "_user,_o")
  (setvar "hpspace" 4)
  (setvar "hpang" 0)
  ;turning echo on
  (setvar "cmdecho" 1)
  ;inform user to select internal point for hatch
  (prompt "\nSelect Internal Point.....")
  ;turning echo off
  (setvar "cmdecho" 0)
  ;starting hatch command
  (command "-bhatch")
  (while (eq (logand (getvar "CmdActive") 1) 1)
    ; get user's input
    (command pause)
    ;_ closes while
    )
  ;setting old vars
  (setvar "hpname" oldhpname)
  (setvar "hpspace" oldhpspace)
  (setvar "hpang" oldhpang)
  (setvar "clayer" clay)
  (setvar "cmdecho" echo)
  (princ)
  )
(princ)

;;**********************
;;*  End of Routine    *
;;**********************

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Question about naming LISP files & defun
« Reply #1 on: March 10, 2004, 12:48:21 PM »
The file names are great, easy to figure out. As far as naming the defun's, what I use sometimes is a big ol long name for the main defun of the app. i.e.
Code: [Select]

(defun this-is-a-long-descriptive-name ().....

then use a calling function at the bottom of the file. i.e
Code: [Select]

(defun c:ld () (this-is-a-long-descriptive-name)

Many times when doing programs for someone else I will compile the source into a .vlx and let the person(s) who are going to be using the program create a calling function outside of the .vlx that best suites their work habit.

Side note about your code:
You should localize all those variables. <G>
TheSwamp.org  (serving the CAD community since 2003)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Question about naming LISP files & defun
« Reply #2 on: March 10, 2004, 12:52:17 PM »
Quote from: Mark Thomas
You should localize all those variables

I concur
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Question about naming LISP files & defun
« Reply #3 on: March 10, 2004, 01:09:50 PM »
Quote from: Keith
Quote from: Mark Thomas
You should localize all those variables

I concur


I'll get to that soon.  I was reading on that, and never finished.

I think I'm going to defun each LISP I make with the actual LISP name.  Would that be ok?  And as far as VLX...haven't gotten to that either...self teaching...

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Question about naming LISP files & defun
« Reply #4 on: March 10, 2004, 01:33:48 PM »
Quote from: Dommy2Hotty
I think I'm going to defun each LISP I make with the actual LISP name.  Would that be ok?

I do that most of the time myself, it's really personal preference.
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
Question about naming LISP files & defun
« Reply #5 on: March 10, 2004, 02:27:29 PM »
I agree with Mark; nice descriptive names (but do they have to be defined as commands if they'll simply be called by buttons?)
The CMDACTIVE loop is a splendid feature.

If all routines will be doing the same stuff, more or less, you might want to consider writing a main function and pass the data that change as argument/arguments. For example:

Code: [Select]

(defun setHatchAndLayer (hname)
  ;getting current vars
  (setq clay (getvar "clayer"))
  (setq echo (getvar "cmdecho"))

  ;; .. etc. etc...

  ;creating layer hname
  (command "-layer" "m" hname "c" "251" "" "")
  ;setting hatch vars
  (setvar "hpname" "_user,_o")

  ;; .. etc. etc...

  (princ)
)


(defun c:Siding4 () (setHatchAndLayer "EL-HATCH-SIDING"))

(defun c:Brick () (setHatchAndLayer "EL-HATCH-BRICK"))

.. etc ...

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Question about naming LISP files & defun
« Reply #6 on: March 10, 2004, 02:35:31 PM »
Hmmm....I'll have to look into that one...and the cmdactive I cribbed from someone...I think it was from here...it was added to my rod and shelf lisp...can't say I came up with that one my own... :twisted: