Author Topic: Determining Overlay or Attached via Object DBX ...  (Read 4221 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Determining Overlay or Attached via Object DBX ...
« on: March 16, 2006, 04:42:14 PM »
In a visual basic thread there's a discussion regarding grabbing the attach state (overlay / attach). Quite frankly it's a pain using the object model, at least based on my investigations many years ago.

Here's how I do it in lisp for documents opened via Object DBX (not for the active documents collection et al, see brief comment in the function declaration). Sorry, it's not overlay documented, and well, I'm playing the "I don't have time card".

An aside, I made loose reference to the function below (part of a large app I wrote for one of my clients called 'Carnivore') in this conversation with Mr. Madsen many moons ago, you may find it interesting; or not.

FWIW ... Cheers.

Code: [Select]
(defun GetXrefsAttachState ( AxDbDocument / _Put _IncHex _Main )

    ;;  GetXrefsAttachState
    ;;
    ;;  Use to get the attach / oerlay state from ObjectDBX
    ;;  documents. While you can use on 'normal' documents, i.e.
    ;;  like the active document, that would be dumb (use
    ;;  traditional dxf methods instead).
    ;;
    ;;  typical call and results
    ;;
    ;;  (GetXrefsAttachState ValidAxDbDocument)
    ;;
    ;;  (   
    ;;      ("Drawing1" "Attach" 1)
    ;;      ("Drawing2" "Overlay" 1)
    ;;      ("Drawing3" "Overlay" 2)
    ;;  )
    ;;
    ;;  The number indicates the xref instances found

    (defun _Put ( item position lst )
        (   (lambda ( i )           
                (mapcar
                   '(lambda ( x )
                        (if (eq position (setq i (1+ i)))
                            item
                            x
                        )
                    )
                    lst
                )
            )
            -1
        )   
    )

    (defun _IncHex ( hex )
   
        (   (lambda ( lst i / j a b )

                (while (setq a (nth (setq i (1+ i)) lst))
                    (cond
                        (   (< 70 a) ; "G" and greater
                            (setq lst
                                (if (setq b (nth (setq j (1+ i)) lst))
                                    (_Put (1+ b) j (_Put 48 i lst))
                                    (append (_Put 48 i lst) (list 49))
                                )
                            )
                        )
                        (   (eq 58 a) ; ":"
                            (setq lst (_Put 65 i lst)) ; replace w/"A"
                        )
                    )
                )

                (vl-list->string (reverse lst))
               
            )

            (cons
                (1+
                    (car
                        (setq lst
                            (reverse
                                (vl-string->list
                                    (strcase hex)
                                )
                            )
                        )
                    )
                )
                (cdr lst)
            )

            -1
        )
       
    )   

    (defun _Main ( AxDbDocument / Object Ename Data Result )
   
        (vlax-for Block

            (vlax-get-property
                AxDbDocument
               'Blocks
            )

            (cond

                (   (and

                        (eq :vlax-true
                            (vlax-get-property
                                Block
                               'IsXref
                            )
                        )

                        (null
                            (vl-catch-all-error-p
                                (setq Object
                                    (vl-catch-all-apply
                                       'vlax-invoke-method
                                        (list
                                            AxDbDocument
                                           'HandleToObject
                                            (_IncHex
                                                (vlax-get-property
                                                    Block
                                                   'Handle
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )

                        (null
                            (vl-catch-all-error-p
                                (setq Ename
                                    (vl-catch-all-apply
                                        'vlax-vla-object->ename
                                        (list Object)
                                    )
                                )
                            )
                        )

                        (null
                            (vl-catch-all-error-p
                                (setq Data
                                    (vl-catch-all-apply
                                       'entget
                                        (list Ename)
                                    )
                                )
                            )
                        )
                        (eq "BLOCK" (cdr (assoc 0 Data)))
                        ;;  If you want this is where'd you'd
                        ;;  add additional properties like the
                        ;;  xref path, flag values ad nauseum.
                    )

                    (setq Result
                        (cons
                            (list
                                (cdr (assoc 2 Data))
                                (if (eq 8 (logand 8 (cdr (assoc 70 Data))))
                                    "Overlay"
                                    "Attach"
                                )
                                (length
                                    (vl-remove-if-not
                                       '(lambda (x) (eq 331 (car x)))
                                        (entget (vlax-vla-object->ename Block))
                                    )
                                )

                            )
                            Result
                        )
                    )
                )
            )
        )

        Result

    )
   
    (_Main AxDbDocument)
   
)

Cludgy? Perhaps. It is what it is and offered at face value.
« Last Edit: March 16, 2006, 07:07:41 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Determining Overlay or Attached via Object DBX ...
« Reply #1 on: March 16, 2006, 05:10:30 PM »
Thanks for sharing Michael....and for making me understand why my VBA solution was "relatively easy". I see now that it will not work in anything but the activedocument........

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Determining Overlay or Attached via Object DBX ...
« Reply #2 on: March 16, 2006, 06:27:40 PM »
My pleasure Jeff.

It's pretty old code, and was experimental at that, so like a lot of things I post I wouldn't take it as absolute, but rather as "there goes Michael again, interesting tangent but there may be a better way". A pivot point if you will.

<another tangent> I still think the object model with regards to xrefs wasn't well thought out at all. </another tangent>
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Determining Overlay or Attached via Object DBX ...
« Reply #3 on: March 16, 2006, 07:46:07 PM »
<another tangent> I still think the object model with regards to xrefs wasn't well thought out at all. </another tangent>
Among other things.......and to think that we've been asking for soemthing better for years and it is still the same in 2007.....

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Determining Overlay or Attached via Object DBX ...
« Reply #4 on: March 16, 2006, 08:21:34 PM »
The only thing more pathetic would be them trying to pass that off as a desire to prevent legacy applications from being broken. I'd call pure BS on that, they have no such desire or concern.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst