Bubble for AutoCAD
The free information assistant for AutoCAD users


How to write a Plug-in:

How do I write a plug-in for Bubble? It's easy if you know Autolisp. Just follow these steps. Note that plug-ins only work in AutoCAD 2000 and beyond. No R14. No LT:

1. Create a new Autolisp file. Add your header (a comment):

;; -----------------------------------------------------------------
;; Bubble 2: My Bubble PlugIn 1.0 - (c) 2002 Asuni CAD
;; -----------------------------------------------------------------

2. Add this loader function AS IT IS. You should not modify it:

;; That's the loader function
;; DO NOT MODIFY
(defun ASUNI:BUBBLE:AddPlugIn (PlgInFunction)
  (if ASUNI:BUBBLE:GETDATA
    (setq ASUNI:BUBBLE:GETDATA
      (append ASUNI:BUBBLE:GETDATA
        (list
          '(setq temp ASUNI:BUBBLE:DATA)
          (list (read PlgInFunction) 'handle)
          '(setq ASUNI:BUBBLE:DATA 
             (append temp '("[-]") ASUNI:BUBBLE:DATA)
          )
          '(princ)
        )
      )
    )
    (progn
      (defun-q ASUNI:BUBBLE:GETDATA (handle / temp)
        (setq ASUNI:BUBBLE:OBJECT nil)
      )
      (setq ASUNI:BUBBLE:GETDATA
        (append ASUNI:BUBBLE:GETDATA
          (list
            (list (read PlgInFunction) 'handle)
            '(princ)
          )
        )
      )
    )
  )
)

3. Next there is the function that does the job. The name of the function should be preceded with "ASUNI:BUBBLE:" as in the sample. This is to avoid collision with other Autolisp functions. 

DATA PASSED TO THE FUNCTION:

This function recieves a parameter called "handle" that has the entity handle of the object that Bubble is trying to show. 

DATA RETURNED FROM THE FUNCTION TO BUBBLE:

This function returns the information to Bubble in 2 variables:

ASUNI:BUBBLE:DATA - The information to be shown by Bubble right now, as a list of lists consisting in name and value of property. 
ASUNI:BUBBLE:OBJECT - The name of the object. If you give the object a name, only your information and the common properties are shown for the object. If this variable is nil, the data is added to the end of the current information list.

(defun ASUNI:BUBBLE:MyBpiPlugIn (handle / ename eget p1 p2)
  (setq ename (handent handle))
  (setq ASUNI:BUBBLE:DATA nil)
  ;; if it is a line
  (if (and ename (= "LINE" (cdr (assoc 0 (setq eget (entget ename))))))
    (progn
      (setq p1 (cdr (assoc 10 eget)))
      (setq p2 (cdr (assoc 11 eget)))
      (setq ASUNI:BUBBLE:OBJECT "MyLine")
      (setq ASUNI:BUBBLE:DATA
        (list
          (if ASUNI:BUBBLE:MyBpi:MyLine:DeltaX
            (strcat "DeltaX: " (rtos (abs (- (car p2) (car p1)))))
          )
          (if ASUNI:BUBBLE:MyBpi:MyLine:DeltaY
            (strcat "DeltaY: " (rtos (abs (- (cadr p2) (cadr p1)))))
          )
          (if ASUNI:BUBBLE:MyBpi:MyLine:DeltaZ
            (strcat "DeltaZ: " (rtos (abs (- (caddr p2) (caddr p1)))))
          )
	)
      )
    )
  )
  (princ)
)
 

4. Then we define the data structure needed by Bubble to show our plug-in properties in Bubble own window, so the user selects which information is shown. It is a list consisting of the following components:

  • A handle of the plug-in. Bubble uses it to create Autolisp data variables. It must be also the folder name under the Plugins folder. 
  • A description (used in the properties window)
  • The name of the Plug-in icon. (This parameter is optional, if it's not used then a default icon is used.)
  • A list for each object with:
    • Handle of the object
    • Name of the object icon (ICO file) to be associated with the object in the properties window. (this parameter is optional, if not used a default icon is used)
    • A list with pairs: handle of the property and actual value (T = is on, false = is off)

Bubble creates variables based on the handles with the following naming system:

ASUNI:BUBBLE:[PlugInHandle]:[ObjectHandle]:[PropertyHandle]

The value is T, if the property is on, or nil, if the property is off.

(setq ASUNI:BUBBLE:PROPS
 '(("MyBpi" "My Bubble Plugin"
    ("MyLine" "MyLine.ico"
      ("DeltaX" T)
      ("DeltaY" T)
      ("DeltaZ" T)
    )
  ))
)

In this sample, Bubble makes the following Autolisp variables:

  • ASUNI:BUBBLE:MyBpi:MyLine:DeltaX
  • ASUNI:BUBBLE:MyBpi:MyLine:DeltaY
  • ASUNI:BUBBLE:MyBpi:MyLine:DeltaZ

that are used in the ASUNI:BUBBLE:MyBpiPlugIn function.

 

5. The last function does the trick. It tells Bubble the necessary information about the plug-in. First adds the plugin to the getdata list (so all plugins get information without disturbing the others), using the function ASUNI:BUBBLE:AddPlugIn, defined earlier in the lisp file (step 1). Last thing is telling Bubble "I'm here". This is done with the ASUNI:BUBBLE:LoadProps 

;; Here is where the loading takes place:
(if (null ASUNI:BUBBLE:MyBpi:Loaded)
  (progn
    (princ "\nBubble 2: My Bubble PlugIn 1.0 - (c) 2001 Asuni CAD")
    ;; To avoid multiple loading
    (setq ASUNI:BUBBLE:MyBpi:Loaded T)
    ;; Adds the function to the GetData pool:
    (ASUNI:BUBBLE:AddPlugIn "ASUNI:BUBBLE:MyBpiPlugIn")
    ;; Load the Properties in Bubble:
    (ASUNI:BUBBLE:LoadProps)
  )
)

 

 


(c) 2006, Asuni CAD - Legal Notice
webmaster