Jump to content

insert custom properties from DWGPROPS in lisp as variabel


Manuel_Kunde

Recommended Posts

  

Hi all, is it possible to read attributes or properties from the _DWGPROPS and list them in a Lisp e.g. as variables?

I need the yellow marked attribute (OD2485), which always has a different number.

 

image.thumb.png.2eff240e6774a0119f073e44684ec8ba.png

 

(defun c:dropsforatts ()
  (setq (vla-get-ActiveDocument
        (vlax-get-acad-object))
        (vla-get-SummaryInfo doc)
  )
  (setq i 0)
  (setq i 5)
)

 

I would then like to insert this variable into a file path in a Lisp.

 

(defun c:tempsave ()
  (getvar "DWGNAME")
  (getvar "DWGPREFIX")
      (command "_+saveas"
               "G"
               "2018dwg"
               "2018(LT2018)"
               ("F:\\\\Clients\\CT2485\\OD2485\\Planning" ;i need the OD2485 as a variabel from the DWGPROPS
                       (strcat (substr (getvar "DWGNAME") 1 8) "_temp")
               )
      )
)

 

Edited by Manuel_Kunde
Link to comment
Share on other sites

(defun ordnum (/ num)
 (setq num (reverse (cdr (reverse (vl-string-search-t "\\" (getvar "DWGPREFIX"))))))
 (setq ordernumber (substr str (+ (car (cdr (reverse num))) 2) (1- (- (last num) (car (cdr (reverse num)))))))
)

;;; *************************FUNCTION VL-STRING-SEARCH-T*****************************

(defun vl-string-search-t (elemento stringa / numero listaposizioni contatore)
 (setq contatore 0
       listaposizioni '()
       numero 0
 )
 (while	numero 
  (setq numero (vl-string-search elemento stringa contatore))
  (if numero
   (progn
    (setq listaposizioni (consr numero listaposizioni)
          contatore (+ numero (strlen elemento))
    )
   ) 
  ) 
 )
 listaposizioni
)

 

This is how it should go. I used a custom function: vl-string-search-t, which allows you to find all substrings instead of just one like the vl-string-search function.

Edited by confutatis
Link to comment
Share on other sites

;;; *********************************CONSR FUNCTION*************************************
Inserts an item at the bottom of the list, not at the beginning like the cons function

(defun consr (element lista)
 (reverse (cons element (reverse lista)))
)

 

Oops, I forgot another custom function to the previous program....

Link to comment
Share on other sites

If you run this you will see current dgwprops 

 

(vlax-dump-object (setq prop (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object)))))
 

so just use

 

(setq prop (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object))))

 

Edited by BIGAL
Link to comment
Share on other sites

6 hours ago, BIGAL said:

If you run this you will see current dgwprops 

 

(vlax-dump-object (setq prop (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object)))))
 

so just use

 

(setq prop (vla-get-odernumber (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object)))))

 

 

The vla-get "Ordernumber" doesn`t work. It says "no function definition: VLA-GET-ordernumber".

Link to comment
Share on other sites

I'd recomend using vla-GetCustomByIndex & vla-setCustomByKey for reading and setting them.

This macro sets up the custom properties for my drawings:

;   Macro: ^P(or CustomPropsLeon (load "CustomPropsLeon.lsp"));CustomPropsLeon
;   Command line: (load "CustomPropsLeon.lsp") CustomPropsLeon
(defun C:CustomPropsLeon ( / doc SummaryInfo KeyCount KeyValue EngOfRec EOR dcl_id SIZ)
  (setq doc (vla-Get-ActiveDocument (vlax-Get-Acad-Object))
		SummaryInfo (vla-Get-SummaryInfo doc)
  ); setq
  (if(=(vla-get-Title SummaryInfo) "")(vla-put-Title SummaryInfo (vl-filename-base (getvar "dwgname"))))
  (if(=(vla-get-Subject SummaryInfo) "")(vla-put-Subject SummaryInfo "My Subject"))
  (if(=(vla-get-HyperlinkBase SummaryInfo) "")(vla-put-HyperlinkBase SummaryInfo "http://beauford.altervista.org/"))
  (GLBLATTCHG "11×17" "#P" (strcat "%<\\AcExpr %<\\AcObjProp Object(%<\\_ObjId " (LM:objectid (vla-get-layouts (LM:acdoc))) ">%).Count>%-1 >%"))
  (defun AddCustomByKey (key / )
	(setq KeyCount 0 ; placeholder for CustProp position
		  KeyValue nil ; String value
	); setq
	; http://forums.augi.com/showthread.php?50050-Check-if-Custom-Drawing-Property-exists&p=749175&viewfull=1#post749175
	(while (and (null KeyValue)(< KeyCount (vla-NumCustomInfo SummaryInfo)))
	  (vla-GetCustomByIndex
		SummaryInfo
		KeyCount
		'TempKeyName
		'TempKeyValue
	  ); vla-GetCustomByIndex
	  (if	(= TempKeyName Key)
		(setq KeyValue TempKeyValue)
	  ); if
	  (setq KeyCount (1+ KeyCount))
	); while
	(if (= KeyValue nil)
	  (progn
		(vla-AddCustomInfo SummaryInfo key "")
		(setq KeyCount 0)
		(while (and (null KeyValue)(< KeyCount (vla-NumCustomInfo SummaryInfo)))
		  (vla-GetCustomByIndex
			SummaryInfo
			KeyCount
			'TempKeyName
			'TempKeyValue
		  ); vla-GetCustomByIndex
		  (if	(= TempKeyName Key)
			(setq KeyValue TempKeyValue)
		  ); if
		  (setq KeyCount (1+ KeyCount))
		); while
	  ); progn
	); if
  ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/custom-drawing-properties/m-p/2873324#M293972
	(princ "\nPages")(princ (vla-GetCustomByKey SummaryInfo  key 'pval)) ;This will return the custom drawing property named "Signature" in the variable pval
  ) ;defun

  (princ)
);defun
(princ)

I have another that sets the CAD username as "Drawn by" and another with a drop-down dialog box to select the engineer for the signature box and this simple one for referencing the Field Book number the notes are in:

;   Macro: ^P(or FB# (load "FB#.lsp"));FB#
;   Command line: (load "FB#.lsp") FB#
(defun c:FB# (/ dProps dProp)
   (vl-load-com)
   (setq acadObject (vlax-get-acad-object))
   (setq acadDocument (vla-get-ActiveDocument acadObject))
   ;;Get the SummaryInfo
  (setq fieldbook (getstring T "Enter Field Book # "))
   (setq dProps (vlax-get-Property acadDocument 'SummaryInfo))
   ; comment this vla-addCustomInfo if the entries already exist in
   ; the drawing properties, (which they will after running this one time)
  (vla-setCustomByKey dProps "Field Book" fieldbook)
  (vla-getCustomByKey dProps "Field Book" 'myValue)
  (princ (strcat "Field Book # = " myValue "\n"))
  (princ) 
)

 

Link to comment
Share on other sites

Sorry was trying to go step ahead this works and yes but you must know the property name. Above a typo.

 

(setq prop (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object))))
: (vlax-dump-object prop)

; Property values :
;
;   Author = "BIG-Al"
;   Comments = ""
;   HyperlinkBase = ""
;   Keywords = ""
;   LastSavedBy = "wouwe"
;   RevisionNumber = ""
;   Subject = ""
;   Title = "test"
T
: (vla-get-author prop)
"BIG-Al"

: (vla-get-title prop)
"test"

 

 

Also (vla-put-keywords prop "structural")

Edited by BIGAL
Link to comment
Share on other sites

  • 2 weeks later...
On 7/9/2021 at 1:28 AM, BIGAL said:

Sorry was trying to go step ahead this works and yes but you must know the property name. Above a typo.

 


(setq prop (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object))))
: (vlax-dump-object prop)

; Property values :
;
;   Author = "BIG-Al"
;   Comments = ""
;   HyperlinkBase = ""
;   Keywords = ""
;   LastSavedBy = "wouwe"
;   RevisionNumber = ""
;   Subject = ""
;   Title = "test"
T
: (vla-get-author prop)
"BIG-Al"

: (vla-get-title prop)
"test"

 

 

Also (vla-put-keywords prop "structural")

 

Hi guys, I finally made it. For those of you who are looking for the same, here is the code:

 

(defun c:SummaryInfo ()
  
 (vl-load-com)
  
    (setq acadObject (vlax-get-acad-object))
    (setq acadDocument (vla-get-ActiveDocument acadObject))

      (setq dProps (vlax-get-Property acadDocument 'SummaryInfo))
      (vla-getCustomByIndex dProps 5 'myValue1 'myValue2)
      
      (princ myValue2)
      (princ)
  
)
  

 

Under the number dprops (in this case 5) the user-defined properties are listed starting from the top.
'my value 1 = is the left column and 'myvalue2 is the right one.

Thanks so far for helping.

 

Link to comment
Share on other sites

If your going to look at the Autocad database only once you can reduce the number of variables required.

 

(setq acadObject (vlax-get-acad-object))
(setq acadDocument (vla-get-ActiveDocument acadObject))
(setq dProps (vlax-get-Property acadDocument 'SummaryInfo))

(setq acadDocument (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq dProps (vlax-get-Property acadDocument 'SummaryInfo))

or even 
(setq dProps (vlax-get-Property (vla-get-ActiveDocument (vlax-get-acad-object)) 'SummaryInfo))

 

Link to comment
Share on other sites

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...