Author Topic: Define Function  (Read 2235 times)

0 Members and 1 Guest are viewing this topic.

John Hancock

  • Guest
Define Function
« on: December 20, 2007, 01:41:53 PM »
I didn't notice this until I found a lisp that was of great interest to me.  I am use to seeing defun c:\ but this lisp doesn't have it. What's the difference?  I am using r2000. Will I be able to use this lisp?

Jeff_M

  • King Gator
  • Posts: 4100
  • C3D user & customizer
Re: Define Function
« Reply #1 on: December 20, 2007, 01:47:42 PM »
What does it have? Maybe it's just a bunch of lines of lisp that execute when the lisp is loaded? Or a function called from another function, such as: (callthisfromelsewhere)

Tough to say without seeing what you have.

deegeecees

  • Guest
Re: Define Function
« Reply #2 on: December 20, 2007, 01:56:56 PM »
When using the "c:"  parameter, the function name is exposed to the command line, as in native AutoCad commands (i.e. circle, line, etc.), when you wrap it in parenthesis, you keep the function in lisp, therefore enabling it to be called with arguments.

JohnK

  • Administrator
  • Seagull
  • Posts: 10669
Re: Define Function
« Reply #3 on: December 20, 2007, 04:34:21 PM »
*blink* *sigh* ...Oh nevermind. I had just built a function entitled "define" about three weeks ago and this thread title scared me.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

John Hancock

  • Guest
Re: Define Function
« Reply #4 on: December 21, 2007, 11:07:47 AM »
Basically what I am asking is, can I use a lisp program that doesn't have the DEFUN C: and if so how? Can I call it up at the command line? Can I set up a tool bar button for it?
Thanks one and all and Have a Merry Christmas

deegeecees

  • Guest
Re: Define Function
« Reply #5 on: December 21, 2007, 11:10:59 AM »
Yes. Call it up in the command line as such:

(FunctionName)

There may be more than one function defined in the lisp, unless you post it, its up to you to determine which one you need to call to activate it.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Define Function
« Reply #6 on: December 21, 2007, 12:23:49 PM »
Or just add c: infront of the function name?  As long as it doesn't take args.

(defun whatthe ( hasarg / ) - cannot simply add c: becuse it take an arg

(defun whatthe (  / ) - simply add c: (defun c:whatthe (  / )

Mud?
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Define Function
« Reply #7 on: December 21, 2007, 01:03:30 PM »
;;  Just to add my 1¢ to this conversation ... in my own
;;  programming I often write functions --


    (defun myFunction ( arg1 arg2 argn ) (code))
   
;;  and then provide a convenience command wrapper to the same

    (defun c:myCommand ( ) (myFunction arg1 arg2 argn) (code))
   
;;  How about a simple, albeit contrived example MP?     
;;
;;  Let's define a function that takes a single argument, an
;;  AutoCAD document object, and return a list of some of the
;;  properties and their values of its database preferences object.


    (defun GetPreferences ( document / preferences )
   
        ;;  Caller's responsibility to pass a valid document
        ;;  database object. Pass an invalid argument and splat,
        ;;  rhubarb pie in yer face.

       
        (setq preferences
            (vla-get-preferences
                (vla-get-database document)
            )
        )
       
        (mapcar
           '(lambda ( property )
                (cons
                    property
                    (vlax-get-property preferences property)
                )
            )                           
           '(   AllowLongSymbolNames
                ContourlinesPerSurface
                DisplaySilhouette
                Lineweight
                LineweightDisplay
                MaxActiveViewports
                ObjectSortByPlotting
                ObjectSortByPSOutput
                ObjectSortByRedraws
                ObjectSortByRegens
                ObjectSortBySelection
                ObjectSortBySnap
                OLELaunch
                RenderSmoothness
                SegmentPerPolyline
                SolidFill
                TextFrameDisplay
                XRefEdit
                XRefLayerVisibility
            )
        )
    )
   
;;  We can use this function on any valid AutoCAD document,
;;  be it the active document, another document open in the
;;  AutoCAD editor but not active, or one opened via ObjectDBX.
;;
;;  For example, all documents open in the editor:


    (vlax-for document (vla-get-documents (vlax-get-acad-object))
   
        (princ
            (strcat
                "Document name: "
                (vla-get-name document)
                "\n\n"
            )
        )
       
        (princ "Database Preferences:\n\n")
   
        (mapcar 'print (GetPreferences document))
       
        (princ "\n")
       
        (princ)
   
    )

;;  But I digrees.
;;
;;  Most users would have little interest in seeing all this
;;  data for all documents. However a user might be
;;  interested in seeing it for the active document. So
;;  let's make a command wrapper that exploits the
;;  GetPreferences functionality using the active document,
;;  and pretty up the display of the data for the user. 
 

    (defun c:GetPreferences ( / value )
   
        (princ "Database Preferences: \n\n")
   
        (foreach pair
   
            (GetPreferences
                (vla-get-activedocument
                    (vlax-get-acad-object)
                )
            )
           
            (princ
                (strcat
                    "    " ;; indent each record 4 spaces
                    (vl-symbol-name (car pair))
                    " = "
                    (cond
                        ((eq :vlax-true (setq value (cdr pair))) "True")
                        ((eq :vlax-false value) "False")
                        ((vl-prin1-to-string value))                                                       
                    )
                    "\n"                       
                )           
            )
        )                         
   
        (princ)   
   
    )

;;  A call to c:GetPreferences might produce this --
;;
;;      Database Preferences:
;; 
;;          ALLOWLONGSYMBOLNAMES = True
;;          CONTOURLINESPERSURFACE = 4
;;          DISPLAYSILHOUETTE = False
;;          LINEWEIGHT = -1
;;          LINEWEIGHTDISPLAY = False
;;          MAXACTIVEVIEWPORTS = 64
;;          OBJECTSORTBYPLOTTING = True
;;          OBJECTSORTBYPSOUTPUT = True
;;          OBJECTSORTBYREDRAWS = True
;;          OBJECTSORTBYREGENS = True
;;          OBJECTSORTBYSELECTION = True
;;          OBJECTSORTBYSNAP = True
;;          OLELAUNCH = False
;;          RENDERSMOOTHNESS = 0.5
;;          SEGMENTPERPOLYLINE = 8
;;          SOLIDFILL = True
;;          TEXTFRAMEDISPLAY = False
;;          XREFEDIT = True
;;          XREFLAYERVISIBILITY = True   

;;  Tangentially yours, Michael :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

deegeecees

  • Guest
Re: Define Function
« Reply #8 on: December 21, 2007, 01:07:07 PM »
..and thats how we do it downtown (Lemont).

 :-D