Author Topic: Getting xdata  (Read 2112 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Getting xdata
« on: February 02, 2020, 12:30:52 PM »
I'm having trouble with retrieving xdata from this door block enclosed, using the TAG routine.

No results found for "bad argument type <NIL> ; expected SAFEARRAY at [vlax-safearray->list]".
Results for bad argument type <NIL> ; expected SAFEARRAY at [vlax-safearray->list]

Any ideas?



Code: [Select]
(defun ARCH:MsgBox2  (title buttons message time / return WshShell)
  (setq WshShell (vlax-create-object "WScript.Shell"))
  (setq return (vlax-invoke WshShell 'Popup message time title (itoa buttons)))
  (vlax-release-object WshShell)
  return)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;Here is a little example of storing x-data data ActiveX
;;;You have to get used to variants and safearrays to do it.
;;;Peter Jamtgaard
(defun GET-XDATA-DRWDWLVR  (/ ENAM EOBJ XDTYPE XDVALUE)
  (vl-load-com)
  (setq ENAM (cdar OBJX)
        EOBJ (vlax-ename->vla-object ENAM))
  (vla-getXData EOBJ "DRWDWLVR" 'XDTYPE 'XDVALUE)
  (mapcar '(lambda (X Y) (cons X (variant-value Y)))
          (vlax-safearray->list XDTYPE)
          (vlax-safearray->list XDVALUE)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun C:TAG ()   
    (setq scf (getvar "dimscale"))
    (setvar "cmdecho" 0)
    (setq objx (entget (car (entsel "\n* Select Door Wdw to Tag *"))))
    ;;(if (= objx nil)(setq objx (entget (entlast))))
    (setq xdli (cdr (assoc 2 (entget (cdar objx) '("DRWDWLVR")))))
    (setq xszx (substr xdli 5 (- (strlen xdli) 8)))
    (setq insx (cdr (assoc 10 objx)))
    ;;(setq insx (getpoint "\n* Pick Tag point..."))
    (setq angx (distof (princ (cdr (cadr (GET-XDATA-DRWDWLVR)))) 2))
    (setq xdrx (substr xdli 1 (- (strlen xdli) 6)))
    (setq xwdx (substr xdli 1 (- (strlen xdli) 6)))
    (setq xlvx (substr xdli 1 (- (strlen xdli) 6)))
    (setq xdr9 (substr xdli 1 (- (strlen xdli) 9)))
    (setq xwd9 (substr xdli 1 (- (strlen xdli) 9)))
    (setq xlv9 (substr xdli 1 (- (strlen xdli) 9)))
    (if (= M nil)
      (setq M 1))
    (setq nam1 (vl-list->string
                 (vl-remove-if-not
                   '(lambda (x) (< 47 x 58))
                   (vl-string->list (rtos (atoi xszx) 4 0)))))
    (setq nam2 (substr xdli 5 (- (strlen xdli) 8)))
    (setq nam3 (vl-list->string
                 (vl-remove-if-not
                   '(lambda (x) (< 47 x 58))
                   (vl-string->list (rtos (/ (atoi nam2) 2) 4 0)))))
    (setq nam4 (vl-list->string
                 (vl-remove-if-not
                  '(lambda (x) (< 47 x 58))
                   (vl-string->list (rtos (/ (atoi nam2) M) 4 0)))))

(ARCH:MsgBox2
      " Arch2Program© : Message"
      64     
      (strcat
        "\n     DrWdwLvr Tag Settings"
        "\n---------------------------------------------------------------------------"
        "\n     Full Name:\t " xdli
        "\n     Tag Type:\t " (substr xdli 1 (- (strlen xdli) 6))
        "\n     Tag Size:\t " xszx
        "\n     Insert X:\t " (rtos (car insx) 2 2)
        "\n     Insert Y:\t " (rtos (cadr insx) 2 2)
        "\n     Angle:\t " (rtos angx 2 6)
        )
      4)
  )


Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Getting xdata
« Reply #1 on: February 02, 2020, 12:55:39 PM »
Your test.dwg opens and is auto-recovered in 2020, with the block being erased due to wrongObjectType. Tried in 2018 as well.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Getting xdata
« Reply #2 on: February 02, 2020, 01:06:33 PM »
Thanks Jeff

I uploaded a new drawing.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Getting xdata
« Reply #3 on: February 02, 2020, 02:44:37 PM »
The entity does not have xdata for the "DRWDWLVR" application. You should improve your GET-XDATA-DRWDWLVR function: add a non-nil check for XDTYPE (or XDVALUE).

GDF

  • Water Moccasin
  • Posts: 2081
Re: Getting xdata
« Reply #4 on: February 02, 2020, 02:48:05 PM »
I have found the problem. I have done a major overhaul of the routine and have just found a typo in the ADD-XDATA-DRWDWLVR portion of the routine.
(regapp "DRWDWLVR") was misspelled.

Thanks Roy

Code: [Select]
;;;Here is a little example of storing x-data data ActiveX
;;;You have to get used to variants and safearrays to do it.
;;;Peter Jamtgaard
(defun ADD-XDATA-DRWDWLVR  (/ ENAM EOBJ STR)
  (vl-load-com)
  (regapp "DRWDWLVR")
  (setq ENAM (cdar (entget (entlast)))
        EOBJ (vlax-ename->vla-object ENAM)
        STR  (rtos ARCH#ANGL 2 8))
  (vla-setxdata
    EOBJ
    (vlax-make-variant
      (vlax-safearray-fill
        (vlax-make-safearray vlax-vbInteger '(0 . 1))
        '(1001 1000)))
    (vlax-make-variant
      (vlax-safearray-fill
        (vlax-make-safearray vlax-vbVariant '(0 . 1))
        (list "DRWDWLVR" STR))))
  (prin1))
« Last Edit: February 02, 2020, 03:01:27 PM by GDF »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Getting xdata
« Reply #5 on: February 03, 2020, 05:09:12 PM »
Instead of a hard-coded string in multiple locations, create a global variable and reference that everywhere.  Easier to debug, fix, and modify.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

GDF

  • Water Moccasin
  • Posts: 2081
Re: Getting xdata
« Reply #6 on: February 03, 2020, 05:21:57 PM »
The routine is used in another routine to automatically install a door or window in a wall in plan, and later to rotate or mirror the block after insertion. It also automatically fills in the door or window tag by selecting the block.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64