Jump to content

Getting visibilty states using OBDX on a block in another dwg.


Recommended Posts

Posted (edited)

I was wondering if any one has tried getting a dynamic block properties from another dwg. I have this as test code 2nd step is to get inside the dynamic block. It gets the block as "obj" but does not like the getvisibilty properties. Thanks to lee for the Dynamic block code.

 

Lee-mac Dynamic block get-put.lsp

 

; Uses Dynamic block editing code by Lee-mac.com

(if (not LM:setdynpropvalue )(load "Lee-mac Dynamic block get-put"))

(setq dbx
  (vl-catch-all-apply 'vla-getinterfaceobject
      (list (setq app (vlax-get-acad-object))
          (if (< (setq vrs (atoi (getvar 'acadver))) 16)
              "objectdbx.axdbdocument" (strcat "objectdbx.axdbdocument." (itoa vrs))
          )
      )
  )
)
(vla-open dbx "D:\\Acadtemp\\OBDXTEST.dwg")

(setq blks (vla-get-blocks dbx))
(vlax-for blok blks
(if (= (vla-get-name blok) "TA-WINDOW")
(setq obj blok)
)
)

(setq visval (LM:getvisibilityparametername obj))
(setq lst (LM:getdynpropallowedvalues obj visval))
(setq lst (cons "Please choose" lst))
(princ lst)
            
; using lst in further code

 

As a side note did get copyobject to work and could then get properties from entlast, but for various reasons do not want the block in the new dwg, only its visibilty states. Its a 2 part function, currently uses a text file of the states which is to be removed.

Edited by BIGAL
Posted (edited)

Hi BIGAL,

 

I would approach it something like this, using Lee-Macs ObjectDBX Wrapper:

 

Sorry, I have no chance to expand on it at the moment.

 

(defun C:DYNBLOCK-VALUES nil (LM:ODBX '(lambda ( doc ) (dynblock:values)) nil nil)(princ))


(defun dynblock:values	( / nme )

  (setq nme "TA-WINDOW")

  (vlax-for x (vla-get-blocks doc)

    (if	(and (= (vlax-get-property x 'isXref) :vlax-false)
	(= (vlax-get-property x 'isXref) :vlax-false)
	(=  (vla-get-isdynamicblock x) :vlax-true)
	(eq (strcase (vla-get-name x)) nme)
	)

      (progn

      (setq visval (LM:getvisibilityparametername x))
	  
	  ;...
	  ;....

      )

    )

  )

  (princ)

)




;;-----------------------=={ ObjectDBX Wrapper }==----------------------;;
;;                                                                      ;;
;;  Evaluates a supplied function on all drawings in a given list or    ;;
;;  selected directory.                                                 ;;
;;----------------------------------------------------------------------;;
;;  Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com              ;;
;;----------------------------------------------------------------------;;
;;  Arguments:                                                          ;;
;;                                                                      ;;
;;  fun [SYM]                                                           ;;
;;  ---------------------------------                                   ;;
;;  A function requiring a single argument (the VLA Document object),   ;;
;;  and following the 'rules' of ObjectDBX:                             ;;
;;                                                                      ;;
;;  - No SelectionSets               (ssget, ssname, ssdel, etc)        ;;
;;  - No Command Calls               (command "_.line" ... etc)         ;;
;;  - No ent* methods                (entget, entmod, entupd, etc)      ;;
;;  - No Access to System Variables  (setvar, getvar, setvariable, etc) ;;
;;                                                                      ;;
;;  lst [LIST] [Optional]                                               ;;
;;  ---------------------------------                                   ;;
;;  List of DWG Filenames; if nil, BrowseForFolder Dialog is displayed. ;;
;;                                                                      ;;
;;  sav [SYM]                                                           ;;
;;  ---------------------------------                                   ;;
;;  Boolean flag determining whether drawings should be saved following ;;
;;  function evaluation (T=saved, nil=not saved).                       ;;
;;----------------------------------------------------------------------;;
;;  Returns:                                                            ;;
;;                                                                      ;;
;;  List of:                                                            ;;
;;  (                                                                   ;;
;;      (<Drawing Filename> . <Function Result>)                        ;;
;;      (<Drawing Filename> . <Function Result>)                        ;;
;;      ...                                                             ;;
;;      (<Drawing Filename> . <Function Result>)                        ;;
;;  )                                                                   ;;
;;                                                                      ;;
;;  Where:                                                              ;;
;;  <Drawing Filename>                                                  ;;
;;  is the filename of drawing that has been processed.                 ;;
;;                                                                      ;;
;;  <Function Result>                                                   ;;
;;  is the result of evaluating the supplied function on the Document   ;;
;;  Object representing the associated drawing filename.                ;;
;;                                                                      ;;
;;  If an error occurs when evaluating the supplied function the        ;;
;;  Function Result will be nil and the error message will be printed   ;;
;;  to the command-line.                                                ;;
;;----------------------------------------------------------------------;;

(defun LM:ODBX ( fun lst sav / *error* app dbx dir doc dwl err rtn vrs )

    (defun *error* ( msg )
        (if (and (= 'vla-object (type dbx)) (not (vlax-object-released-p dbx)))
            (vlax-release-object dbx)
        )
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )

    (cond
        (   (not
                (or lst
                    (and (setq dir (LM:browseforfolder "Select Folder of Drawings to Process" nil 512))
                         (setq lst (mapcar '(lambda ( x ) (strcat dir "\\" x)) (vl-directory-files dir "*.dwg" 1)))
                    )
                )
            )
            nil
        )
        (   (progn
                (setq dbx
                    (vl-catch-all-apply 'vla-getinterfaceobject
                        (list (setq app (vlax-get-acad-object))
                            (if (< (setq vrs (atoi (getvar 'acadver))) 16)
                                "objectdbx.axdbdocument" (strcat "objectdbx.axdbdocument." (itoa vrs))
                            )
                        )
                    )
                )
                (or (null dbx) (vl-catch-all-error-p dbx))
            )
            (prompt "\nUnable to interface with ObjectDBX.")
        )
        (   t
            (vlax-for doc (vla-get-documents app)
                (setq dwl (cons (cons (strcase (vla-get-fullname doc)) doc) dwl))
            )
            (foreach dwg lst
                (if (or (setq doc (cdr (assoc (strcase dwg) dwl)))
                        (and (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list dbx dwg))))
                             (setq doc dbx)
                        )
                    )
                    (progn
                        (setq rtn
                            (cons
                                (cons dwg
                                    (if (vl-catch-all-error-p (setq err (vl-catch-all-apply fun (list doc))))
                                        (prompt (strcat "\n" dwg "\t" (vl-catch-all-error-message err)))
                                        err
                                    )
                                )
                                rtn
                            )
                        )
                        (if sav (vla-saveas doc dwg))
                    )
                    (princ (strcat "\nError opening file: " (vl-filename-base dwg) ".dwg"))
                )
            )
            (if (= 'vla-object (type dbx))
                (vlax-release-object dbx)
            )
            (reverse rtn)
        )
    )
)

;;------------------=={ Browse for Folder }==-----------------;;
;;                                                            ;;
;;  Displays a dialog prompting the user to select a folder.  ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2013 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  msg - message to display at top of dialog                 ;;
;;  dir - root directory (or nil)                             ;;
;;  flg - bit-coded flag specifying dialog display settings   ;;
;;------------------------------------------------------------;;
;;  Returns:  Selected folder filepath, else nil.             ;;
;;------------------------------------------------------------;;

(defun LM:browseforfolder ( msg dir flg / err fld pth shl slf )
    (setq err
        (vl-catch-all-apply
            (function
                (lambda ( / app hwd )
                    (if (setq app (vlax-get-acad-object)
                              shl (vla-getinterfaceobject app "shell.application")
                              hwd (vl-catch-all-apply 'vla-get-hwnd (list app))
                              fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg flg dir)
                        )
                        (setq slf (vlax-get-property fld 'self)
                              pth (vlax-get-property slf 'path)
                              pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth))
                        )
                    )
                )
            )
        )
    )
    (if slf (vlax-release-object slf))
    (if fld (vlax-release-object fld))
    (if shl (vlax-release-object shl))
    (if (vl-catch-all-error-p err)
        (prompt (vl-catch-all-error-message err))
        pth
    )
)

(vl-load-com)


(princ)

 

Edited by mrharris78
Posted

So this seems to work but is hard code for the task at hand.

; Big thanks to lee-mac for the vis code getting dynamic block visibilty names and OBDX hints.
; BY Alan H March 2024

(defun dynvis ( / dbx blks blok obj vis visvals ans)

(setq dbx
  (vl-catch-all-apply 'vla-getinterfaceobject
      (list (setq app (vlax-get-acad-object))
          (if (< (setq vrs (atoi (getvar 'acadver))) 16)
              "objectdbx.axdbdocument" (strcat "objectdbx.axdbdocument." (itoa vrs))
          )
      )
  )
)

(vla-open dbx "C:\\xxxxxx\\Myour dwg name.dwg") ; your dwg name

(setq blks (vla-get-blocks dbx))
(vlax-for blok blks
  (if (= (vla-get-name blok) "Your dynamic block name")
  (setq obj blok)
  )
)

(setq vis
  (vl-some
     '(lambda ( pair )
          (if
              (and
                  (= 360 (car pair))
                  (= "BLOCKVISIBILITYPARAMETER" (cdr (assoc 0 (entget (cdr pair)))))
              )
              (cdr pair)
          )
      )
      (dictsearch
          (vlax-vla-object->ename (vla-getextensiondictionary obj))
          "ACAD_ENHANCEDBLOCK"
      )
  )
)
(setq visvals '())
(setq visvals (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 303)) (entget vis))))

(if (not AHlstbox)(load "Listbox-AH.lsp"))
(setq ans (nth (ahlstbox "Pick a client" visvals 30 30) visvals ))

(vlax-release-object dbx)

(princ)
)
(dynvis)

Listbox-AH.lsp

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...