objectid question, fields and tables

objectid question, fields and tables

christopher.l.evans
Advocate Advocate
1,629 Views
2 Replies
Message 1 of 3

objectid question, fields and tables

christopher.l.evans
Advocate
Advocate

 

I'm playing around with this code in Autocad Mechanical in Autodesk Product Design Suite Ultimate 2015 but end use will be Autocad Mechanical in Autodesk Product Design Suite Ultimate 2017.

 

When I use the following code to create a field in a table I get the following;

 

%<\AcObjProp Object(%<\_ObjId 45>%).Area \f "%lu2%pr2">%

 

When I create the field manually I get the following;

 

%<\AcObjProp.16.2 Object(%<\_ObjId 8796087808832>%).Area \f "%lu2%pr2">%

 

;; Put Field in Cell, by Lee McDonnell 11.07.2009

(defun c:putfld (/ *error* doc spc chx ent Obj tStr
                   grdat gr dat osPt tss lst row col)
  (vl-load-com)

  (defun *error* (msg)
    (and tObj
      (not
        (vlax-erased-p tObj))
          (vla-delete tObj))
    (if (not
          (wcmatch
            (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
      (princ
        (strcat
          "\n<< Error: " msg " >>"))
      (princ "\n*Cancel*"))
    (princ))
  
  (setq doc (vla-get-ActiveDocument
              (vlax-get-Acad-Object))
        spc (if
              (zerop
                (vla-get-activespace doc))
              (if (= (vla-get-mspace doc) :vlax-true)
                (vla-get-modelspace doc) ; Vport
                (vla-get-paperspace doc))
              (vla-get-modelspace doc)))
  (or *mac (setq *mac "Select"))
  (initget "Select Polyline")
  (setq chx
    (getkword
      (strcat "\nSelect Object or Draw Polyline [Sel/Poly] <" *mac "> : ")))
  (or (not chx) (setq *mac chx))
  (cond
    ((eq "Select" *mac)
     (while
       (progn
         (setq ent (car (entsel "\nSelect Object: ")))
         (cond
           ((eq 'ENAME (type ent))
            (if
              (not
                (vlax-property-available-p
                  (setq Obj
                    (vlax-ename->vla-object ent)) 'Area))
              (princ "\n** Invalid Object Selected **")))
           (t (princ "\n** Nothing Selected **"))))))
    ((eq "Polyline" *mac)
     (command "_.pline")
     (while
       (eq 1
         (logand 1
           (getvar 'CMDACTIVE)))
       (command pause))
     (setq Obj
       (vlax-ename->vla-object
         (entlast)))))
  (if Obj
    (progn
      (setq tStr
        (strcat
          "%<\\AcObjProp Object(%<\\_ObjId "
            (vl-princ-to-string
              (vla-get-Objectid Obj))
              ">%).Area \\f \"%lu2%pr2\">%"))
        (setq tObj
          (vla-addMText spc
            (vlax-3D-point '(0 0 0)) 0 tStr))
      (vla-put-visible tObj :vlax-false)          
      (while
        (progn
          (setq grdat (grread t 15 0)
                gr (car grdat) dat (cadr grdat))
          (cond
            ((and (eq 5 gr) (listp dat))
             (redraw)
             (vla-put-visible tObj :vlax-true)
             (if (and (< 0 (getvar "OSMODE") 16383)
                      (setq osPt
                        (osnap dat
                          (osLst
                            (getvar "OSMODE")))))
               (progn
                 (osMark osPt) (setq dat osPt)))
             (vla-move tObj
               (vla-get-InsertionPoint tObj)
                 (vlax-3D-point dat))
             t)
            ((eq 2 gr)
             (cond
               ((vl-position dat '(32 13))
               nil)
               ((eq 6 dat)
                (cond ((< 0 (getvar "OSMODE") 16384)
                       (setvar "OSMODE"
                         (+ 16384
                            (getvar "OSMODE"))))
                      (t (setvar "OSMODE"
                           (- (getvar "OSMODE") 16384)))))
               (t t)))             
            ((eq 25 gr)
             (and tObj
                  (not
                    (vlax-erased-p tObj))
                      (vla-delete tObj))
             nil)
            ((eq 3 gr)
             (if
               (and
                 (setq tss
                   (ssget "_X" '((0 . "ACAD_TABLE"))))
                 (setq lst (car
                   (vl-remove-if 'null
                     (mapcar
                       (function
                         (lambda (tab)
                           (if
                             (eq :vlax-true
                               (vla-HitTest tab
                                 (vlax-3D-point
                                   (trans dat 1 0))
                                     (vlax-3D-point
                                       (trans
                                         (getvar 'VIEWDIR) 1 0)) 'row 'col))
                             (list tab row col))))
                       (mapcar 'vlax-ename->vla-object
                         (mapcar 'cadr (ssnamex tss))))))))
               (and
                 (not             
                   (apply 'vla-SetText
                     (append lst (list tStr)))) tObj
                   (not (vlax-erased-p tObj))
                 (vla-delete tObj)))
             nil)
            (t t))))))
  (princ))

(defun oSlst (os / str cnt)
  (setq str "" cnt 0)
  (if (< 0 os 16383)
    (foreach mod '("_end" "_mid" "_cen" "_nod" "_qua"
                   "_int" "_ins" "_per" "_tan" "_nea"
                   "_non" "_app" "_ext" "_par")
      (if (not (zerop (logand (expt 2 cnt) os)))
        (setq str (strcat str mod (chr 44))))
      (setq cnt (1+ cnt))))
  (vl-string-right-trim (chr 44) str))

(defun osMark (pt / drft osSz osCol ratio bold glst i)
  (setq drft (vla-get-drafting
               (vla-get-preferences
                 (vlax-get-acad-object)))
        osSz (vla-get-AutoSnapMarkerSize drft)
        oscol (vla-get-AutoSnapMarkerColor drft)
        ratio (/ (getvar "VIEWSIZE")
               (cadr (getvar "SCREENSIZE")))
        bold (mapcar
               (function
                 (lambda (x)
                   (* x ratio))) (list (+ osSz 0.5) osSz (- osSz 0.5))) i 0)

  (repeat 50
    (setq glst
      (cons
        (polar '(0 0 0) (* i (/ pi 25.)) 1.) glst) i (1+ i)))      

  (foreach x bold
     (grvecs (append (list oscol) glst (cdr glst) (list (car glst)))
             (list (list  x  0.0 0.0 (car pt))
                   (list 0.0  x  0.0 (cadr pt))
                   (list 0.0 0.0 1.0 0.0)
                   (list 0.0 0.0 0.0 1.0)))))

 

I thought I just needed to add the .16.2 here but that only gave me the following;

 

%<\AcObjProp.16.2 Object(%<\_ObjId 45>%).Area \f "%lu2%pr2">%

 

(strcat
          "%<\\AcObjProp.16.2 Object(%<\\_ObjId "
            (vl-princ-to-string
              (vla-get-Objectid Obj))
              ">%).Area \\f \"%lu2%pr2\">%"))

 

Lastly, I would like to specify a cell range instead of pick cell.  When I search for something to reference I'm getting a lot of datalink excel stuff instead.  If someone has something I can reference like "select table" then "specify cell range" "C2:C20" and it would step through C2, C3 etc.

 

 

0 Likes
Accepted solutions (1)
1,630 Views
2 Replies
Replies (2)
Message 2 of 3

dbroad
Mentor
Mentor
Accepted solution
Message 3 of 3

christopher.l.evans
Advocate
Advocate

Changing to itoa worked great.  Now just to make a selection in modelspace through a vp....

0 Likes