Author Topic: entmake / activex question  (Read 3186 times)

0 Members and 1 Guest are viewing this topic.

gskelly

  • Newt
  • Posts: 185
entmake / activex question
« on: February 15, 2009, 12:00:55 PM »
Hi;

I'm getting a pet project to the almost useful stage. My understanding
of Autolisp is enough to get stuff done and visual lisp is experimental.
I have read in various places it is best to avoid entmake if ActiveX
functions will be used.

If I wish to make use of visual lisp more should I rewrite everything
that uses entmake?

Currently I'm using entmake / entmakex to do things like create
XRECORDS like:

Code: [Select]
(defun nss:txt_pt_to_xrec ( pt_list / k x y z d)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Function to create an xrecord entity from a text point list given as:
;;; (name northing easting elevation decription)
;;; e.g.: ("3" "4957089.60950" "5568211.18416" "99.20000" "DH")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (setq k (car pt_list)              ; The point name is the key
          y (atof (cadr pt_list))      ; The northing is the y
          x (atof (caddr pt_list))     ; The easting is the x
          z (atof (cadddr pt_list))    ; The elevation is the z
          d (last pt_list)             ; The description
    )

    (entmakex
        (list
            '(0 . "XRECORD")
            '(100 . "AcDbXrecord")
            (cons 2 k)
            (list 10 x y z)
            (cons  1 d)
        )
    )
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun nss:txt_pts_to_dict ( pts_list / pt xrecs)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Function to add a list of text point lists to the points dictionary.
;;; A list of text point lists looks like:
;;; (
;;;     ("1" "4957000.00000" "5568000.00000" "97.00000" "DH")
;;;     ("2" "4957170.06183" "5568132.61079" "97.32800" "DH")
;;;     ("3" "4957089.60950" "5568211.18416" "99.20000" "DH")
;;; )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (setq xrecs (mapcar '(lambda(x)(nss:txt_pt_to_xrec x)) pts_list))
    (setq pts_list nil)
    (mapcar '(lambda(x)(nss:put_xrec_in_dict x (nss:ptdict))) xrecs)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

and using dictionaries created like:
Code: [Select]
(defun nss:get_dict (dname parent_dict / dict)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Function to get a dictionary by name from a given parent. A new dictionary
;;; will be created if one cannot be found.
;;; Input: dname <-- string name of dictionary to get or make
;;;                  if it does not exist.
;;;        parent_dict <-- the dictionary entity the dictionary of interest
;;;                        is in. Use (namedobjdict) to insert in the NOD.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;test if dictionary is already present in the main dictionary
    (and DEBUG
        (princ (strcat "\nDEBUG: nss:get_dict: getting " dname))
    )
    (if (not (setq dict (dictsearch parent_dict dname)))
        ;;if not found create a new one
        (progn
            (and DEBUG
                (princ "\nDEBUG: nss:get_dict: not found.")
            )
            (setq dict
                (entmakex
                    (list
                        '(0 . "DICTIONARY")
                        '(100 . "AcDbDictionary")
                    )
                )
            )
            ;and add it to the parent dictionary
            (and DEBUG
                (princ "\nDEBUG: nss:get_dict: adding dict.")
            )
            (setq dict
                (dictadd parent_dict dname dict)
            )
        );_ end progn
        (progn
            ;;else return its entity name
            (and DEBUG
                (princ "\nDEBUG: nss:get_dict: found dict.")
            )
            (setq dict (cdr (assoc -1 dict)))
        );_ end else progn
    );_ end if
);_ end defun
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Thanks.
Bricscad v12

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8702
  • AKA Daniel
Re: entmake / activex question
« Reply #1 on: February 15, 2009, 12:51:33 PM »
Personally, I wouldn’t change a thing.. unless you must ... or you just want to learn.
Entmake is probably faster && I hate syntax like vlax-variant, vlax-safearray…   :-P

Why would you want to mess-up that Beautiful code  8-)

Dan
 

gskelly

  • Newt
  • Posts: 185
Re: entmake / activex question
« Reply #2 on: February 15, 2009, 08:11:06 PM »
Thanks Dan.

 I do want to learn more about using the ActiveX stuff.... mostly for reactors I think. Then again I been wanting to learn about the ObjectARX (or BRX) stuff too for custom entities I just need more time in a day :-D

I don't understand the why and when related to the warnings about mixing the two and that rattles around in my head each time I use entmake... and if I can sit here and talk about it I can go off and try to find the answer... see ya  :-)
Bricscad v12

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8702
  • AKA Daniel
Re: entmake / activex question
« Reply #3 on: February 16, 2009, 12:28:51 AM »
Out of curiosity, I looked through my old lisp libraries and I never really used ActiveX for XData, Xrecords or Selection Sets, I did make/modify all my entities via ActiveX.
Weird  :-o

gskelly

  • Newt
  • Posts: 185
Re: entmake / activex question
« Reply #4 on: February 16, 2009, 07:58:19 AM »
I've received a reply from Bricscad support... there is no known conflict when mixing entmake and ActiveX. I guess I will try to find an example to test.

Does anyone know off the top of their head where or how entmake and ActiveX should be in conflict?

Thanks
Bricscad v12

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: entmake / activex question
« Reply #5 on: February 16, 2009, 10:18:13 AM »
If I remember correctly the conflict comes from using entmake and
Code: [Select]
  (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vla-StartUndoMark (vla-get-activedocument (vlax-get-acad-object)))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

gskelly

  • Newt
  • Posts: 185
Re: entmake / activex question
« Reply #6 on: February 16, 2009, 11:18:52 AM »
If I remember correctly the conflict comes from using entmake and
Code: [Select]
  (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vla-StartUndoMark (vla-get-activedocument (vlax-get-acad-object)))

Thanks!

I'll look into this tonight.
Bricscad v12

gskelly

  • Newt
  • Posts: 185
Re: entmake / activex question
« Reply #7 on: February 17, 2009, 09:26:19 PM »
I have tried a few things but have not experienced any troubles. I am using the vla-EndUndoMark and vla-StartUndoMark then making several calls to the functions below in a couple of test routines.  I run them several times creating points and blocks and the undo / redo seems to work fine also. (I think I made the block properly... they insert ok from the command line at least.)

Is mixed entmake / ActiveX only a problem in older Autocad releases (like pre-2004) and backward compatibility is the reasoning for the advice?

Signed Curious  :lol:

Code: [Select]
(defun check_pt ( pt )
    (and
        (listp pt)
        (>= (length pt) 3)
        (numberp (car   pt))
        (numberp (cadr  pt))
        (numberp (caddr pt))
    )
)
 
(defun make_attr ( tag val ask pt_at lay / )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Simple test funtion to create an attribute entity using entmake.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (and
        (check_pt pt_at)
        (snvalid lay 0)
        (not (wcmatch tag "*[ ]*"))
        (/= tag "")
        (setq ent
            (entmake
                (list
                   '(0 . "ATTDEF")
                    (cons 8 lay)
                    (cons 1  val)
                    (cons 2  tag)
                    (cons 3  ask)
                   '(10 0 0 0)
                    (cons 11 pt_at)
                   '(40 . 2.5)
                   '(70 . 0)
                   '(74 . 2)
                )
            )
        )
    )
    ent
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun make_node ( pt_at lay / ent)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Simple test funtion to create a point entity using entmake
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (and
        (check_pt pt_at)
        (snvalid lay 0)
        (setq ent
            (entmake
                (list
                    '( 0 . "POINT")
                     (cons 8 lay)
                     (cons 10 pt_at)))
        )
    )
    ent
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   
   
(defun make_block ( block_name base_pt / )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Simple test funtion to create a block entity
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    ;write block header
    (and
        (snvalid block_name 0)
        (check_pt base_pt)
        (entmake
            (list   '(0 . "BLOCK")
                     (cons 2 block_name)
                    '(70 . 2)          ; we will have non-const attr
                    (cons '10 base_pt)))
       
        (make_node base_pt "GREG_POINT")
        (make_attr
            "ID" "id" "Enter id value: "
            (mapcar '+ base_pt '(2.5 0.0 0.0))
            "GREG_ATTR"
        )
        (setq block_name (entmake '((0 . "ENDBLK"))))
    )
    block_name
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Bricscad v12