ChirilaDan Posted November 19, 2010 Posted November 19, 2010 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 Quote
ChirilaDan Posted November 19, 2010 Author Posted November 19, 2010 by custom properties i mean "dwgprops" and custom tab. Quote
lfe011969 Posted November 19, 2010 Posted November 19, 2010 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. Quote
ChirilaDan Posted November 19, 2010 Author Posted November 19, 2010 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 Quote
ChirilaDan Posted November 19, 2010 Author Posted November 19, 2010 how can i edit this code to suite my needs? sorry if my english is bad! Quote
fixo Posted November 21, 2010 Posted November 21, 2010 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) ) Quote
ChirilaDan Posted December 13, 2010 Author Posted December 13, 2010 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. Quote
fixo Posted December 14, 2010 Posted December 14, 2010 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 Quote
ChirilaDan Posted December 14, 2010 Author Posted December 14, 2010 Post your xml file as attachment to see its structure Here is a sample of cpxmlfile sample.txt Quote
fixo Posted December 14, 2010 Posted December 14, 2010 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'~ Quote
ChirilaDan Posted February 24, 2011 Author Posted February 24, 2011 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. Quote
fixo Posted February 24, 2011 Posted February 24, 2011 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 Quote
ChirilaDan Posted February 25, 2011 Author Posted February 25, 2011 where i have to use "foreach" or "mapcar". Quote
fixo Posted February 27, 2011 Posted February 27, 2011 where i have to use "foreach" or "mapcar". Sorry this is a bad explanation Try explain your goal again You might want to use this helper: http://translation2.paralink.com/translation.asp ~'J'~ Quote
VVA Posted March 2, 2011 Posted March 2, 2011 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 LISP to edit DWGPROPS Error when adding custom drawing property api-xml.lsp (need registrations) Quote
cadplayer Posted June 19, 2013 Posted June 19, 2013 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) ) Quote
VVA Posted June 25, 2013 Posted June 25, 2013 Hi! what is if I have more childs:lol: [/code] Try to use -- VovKa's XML Functions -- Look post #8 or read XML into list Quote
cadplayer Posted June 26, 2013 Posted June 26, 2013 Thank you VVA that was exactly I was looking for:D Quote
Recommended Posts
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.