Jump to content

Recommended Posts

Posted

I need some lisp or vba app so that i can fill in autocad custom properties values from an xml file. I am setting up a dwt file to use fields based on that custom properties. Thanks

Posted

by custom properties i mean "dwgprops" and custom tab.

Posted

I have no idea how to import values from an xml file but below is one way to add a custom property lisp-wise:

 

(vla-addcustominfo (vla-get-summaryinfo (vla-get-activedocument (vlax-get-acad-object))) PROP_NAME PROP_VALUE)

 

 

Of course you should include some type of check to see if the custom property already exists because the above code won't work if it does.

Posted

it's a good ideea! I have litle kwnolege in lisp or vba programing but i found a vba code witch is similar in a small way to what i need.The code below to specify a drawings custom properties.

 

 

Sub SetCustomDwgProps()

 

 

 

'Lines below set the standard properties

 

ThisDrawing.SummaryInfo.Author = ThisDrawing.GetVariable("LOGINNAME")

 

ThisDrawing.SummaryInfo.Comments = "Comments Created by VisibleVisual"

 

ThisDrawing.SummaryInfo.RevisionNumber = 1

 

ThisDrawing.SummaryInfo.Title = "VisibleVisual Example"

 

ThisDrawing.SummaryInfo.Subject = "Entering Properties"

 

ThisDrawing.SummaryInfo.Keywords = "Example, VBA, Code"

 

 

 

'The lines below create custom properties

 

Call setCustvalue("PLATFORM", ThisDrawing.GetVariable("PLATFORM"))

 

Call setCustvalue("COMPUTER", Environ("ComputerName"))

 

Call setCustvalue("SERIAL", ThisDrawing.GetVariable("_PKSER"))

 

Call setCustvalue("WEBSITE", "www.visiblevisual.com")

 

End Sub

 

 

 

'Set Custom Property Value

 

Sub setCustvalue(key, value)

 

 

 

Dim custvalue As String

 

Set oSumm = ThisDrawing.SummaryInfo

 

On Error Resume Next

 

oSumm.GetCustomByKey key, custvalue

 

On Error GoTo 0

 

 

 

If custvalue = "" Then

 

oSumm.AddCustomInfo key, value

 

Else

 

oSumm.SetCustomByKey key, value

 

End If

 

End Sub

Posted

how can i edit this code to suite my needs? sorry if my english is bad!

Posted
how can i edit this code to suite my needs? sorry if my english is bad!

 

Try something like this

(vl-load-com)
(defun setvalue(info key value)
   (if (vl-catch-all-apply
'vla-removecustombykey
(list info key)
     )
   (vla-addcustominfo info key value)
   (progn
     (vl-catch-all-apply
'vla-removecustombykey
(list info key)
     )
     (vla-addcustominfo info key value)
   )
 )
   )
(defun C:Cust(/ adoc dwgname info user)

 (setq adoc (vla-get-activedocument (vlax-get-acad-object)))

 (setq info (vla-get-SummaryInfo adoc))
 (setq user (getvar "loginname"))
 (setq dwgname (getvar "dwgname"))

 (vl-catch-all-apply
     'vlax-put (list info 'Author user))

 (vl-catch-all-apply
     'vlax-put (list info 'Lastsavedby info user))

 (vl-catch-all-apply
     'vlax-put (list info 'Title dwgname))
 (vl-catch-all-apply
     'vlax-put (list info 'RevisionNumber "RX-100"));etc
;;customs
 (setvalue info "Key001" "Value001")
 (setvalue info "Key002" "Value002")
 (setvalue info"Key0033" "Value003");etc
 (vla-save adoc)
 (princ)
 )

  • 3 weeks later...
Posted

Thanks for your help, but i need a code that could import those custom values "Value001", "Value002", "Value003" etc. from a cpxml file. I have multiple cpxml files, they all have the same tag's but diffrent values. All cpxml files were exported from a database. I created text fields on various titleblocks linked to custom dwg properties.

Posted
Thanks for your help, but i need a code that could import those custom values "Value001", "Value002", "Value003" etc. from a cpxml file. I have multiple cpxml files, they all have the same tag's but diffrent values. All cpxml files were exported from a database. I created text fields on various titleblocks linked to custom dwg properties.

 

Post your xml file as attachment to see its structure

Posted
Post your xml file as attachment to see its structure

Here is a sample of cpxmlfile sample.txt

Posted

Here is just a framework only

try to complete it by yourself

 
;;=====================================
(defun read_by_tags  (xml_doc tag / lst)
 (setq adr_elems (vlax-invoke-method
     xml_doc
     'getelementsbytagname
     tag))
 (setq leng (vlax-get-property adr_elems 'length))
 (setq cnt 0)
 (while (< cnt leng)
   (setq tmp (vlax-get-property
 (vlax-get-property
   (vlax-get-property adr_elems 'Item cnt)
   'firstchild)
 'text))
   (setq lst (cons tmp lst))
   (setq cnt (1+ cnt)))
 (cons tag (list (reverse lst)))
 )
;;=====================================
(defun C:demo(/ adr_elems info srt_elems ssp_elems xml_doc)
(vl-load-com)
(setq xml_doc (vla-getinterfaceobject  (vlax-get-acad-object)"msxml.domdocument"))

(while (not (eq :vlax-true(vlax-get-property xml_doc 'async)));wait for application accessibility
 )
(vlax-invoke-method xml_doc 'load "C:/UsedFiles/sample.cpxml")
(setq info (mapcar  (function (lambda (x)(read_by_tags xml_doc x)))
        (list "ADDRESSID"
       "SIRSUP"
       "SIRUTA");etc. <-- add all of the desired tags here
     )
     )

(if xml_doc (vlax-release-object xml_doc ))
;; --> work with 'info' here, use 'foreach' or 'mapcar' for that
 (princ)
 )

 

~'J'~

  • 2 months later...
Posted

thanks for the help, but if you could help me to the second part of code I would appreciate. I would save many hours of work on autocad with this code running.

Posted
thanks for the help, but if you could help me to the second part of code I would appreciate. I would save many hours of work on autocad with this code running.

 

Sorry don't understand what you mean about 'the second part of code'

please explain me this widely

Posted

where i have to use "foreach" or "mapcar".

  • 2 years later...
Posted

Hi!

 

fixo have done a great start to my whish read xml-files via Lisp. You get it "firstchild" in xml. what is if I have more childs:lol:

CutFillReport - Kopia.xml.txt

 

In this file I can read

(list "AeccCutFillReport"

"GeneratedTime"

"User"

"Drawing"

"VolumeSummary"

"Volume" ???

)

 

But the next is I want the volume results too. Sorry I have transformed your code to my wishes. Hopefully you understand that.

 

;;=====================================
(defun read_by_tags  (xml_doc tag / lst)
   (setq adr_elems (vlax-invoke-method xml_doc 'getelementsbytagname tag))
   (setq leng (vlax-get-property adr_elems 'length))
   (setq cnt 0)
   (while (< cnt leng)
       (setq tmp (vlax-get-property
                     (vlax-get-property
                         (vlax-get-property adr_elems 'Item cnt) 
                     'firstchild 
                     )
                 'text 
                 )
       )
       (setq lst (cons tmp lst))
       (setq cnt (1+ cnt))
       )
   (cons tag (list (reverse lst)))
   )

;;=====================================
(defun C:demo(/
;;;              adr_elems info srt_elems ssp_elems xml_doc
             )
(vl-load-com)
(setq xml_doc (vla-getinterfaceobject  (vlax-get-acad-object)"msxml.domdocument"))

(while (not (eq :vlax-true(vlax-get-property xml_doc 'async)));wait for application accessibility
 )
(vlax-invoke-method xml_doc 'load "C:/temp/CutFillReport.xml")
(setq info (mapcar  (function (lambda (x)(read_by_tags xml_doc x)))
        (list "AeccCutFillReport"
              "GeneratedTime"
              "User"
              "Drawing"
              "VolumeSummary"
              "Volume" ???
              );etc. <-- add all of the desired tags here
     )
     )
(princ info)
;;;(if xml_doc (vlax-release-object xml_doc ))
;; --> work with 'info' here, use 'foreach' or 'mapcar' for that
 (princ)
 )

Posted

Thank you VVA that was exactly I was looking for:D

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