Jump to content

how can i import data from xml file to autocad custom properties?


ChirilaDan

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 3 weeks later...

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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'~

Link to comment
Share on other sites

  • 2 months later...

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 years later...

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

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