我需要使用AutoLISP使用ObjectDBX方法更改绘图属性。这个例程运行正常但不更改属性,你能建议任何代码更改或任何其他方法来实现这个任务吗? 谢谢。
;;;;;;;;;;;;;;;;;;;
(defun DBX_ATT_CHANGE (f)
(vl-load-com)
(setq cadver (substr (getvar "acadver") 1 2))
(setq id (strcat "objectdbx.AxDbDocument." cadver))
(setq dbx (vlax-create-object id))
(vla-open dbx f)
(vlax-for n_object (vla-get-modelspace dbx)
(setq dbx_en (vlax-vla-object->ename n_object))
(setq upc_blkobj (vlax-ename->vla-object dbx_en))
(if (vlax-method-applicable-p upc_blkobj 'GetAttributes)
(progn
(setq upc_attlist
(vlax-invoke upc_blkobj 'GetAttributes)
)
(foreach upc_att upc_attlist
(progn
(if (= (vla-get-tagstring upc_att) (strcase "P_TAG1"))
(vlax-put-property
upc_att
'TextString
"555"
)
)
)
)
)
)
(vlax-release-object upc_blkobj)
)
(vla-saveas dbx dwgfile)
(vlax-release-object dbx)
(prin1)
)
(defun c:test ()
(DBX_ATT_CHANGE
"D:/6. R&D/Delet Group LispDBXapi/7-EU-FE-48-AC-CIOC-SA - Copy.dwg"
)
)
;;;;;;;;;;;;;;;
答案 0 :(得分:2)
您当前的代码中存在一些奇怪的内容:
(setq dbx_en (vlax-vla-object->ename n_object))
(setq upc_blkobj (vlax-ename->vla-object dbx_en))
您正在将vla-object n_object
转换为实体名称dbx_en
,然后将此实体名称转换回vla-object upc_blkobj
。这两行是多余的,因为您可以直接使用n_object
变量。
(= (vla-get-tagstring upc_att) (strcase "P_TAG1"))
您正在使用strcase
将文字大写字符串P_TAG1
转换为大写,然后将此大写字符串与可能大于或不大写的字符串进行比较 - 我相信此行应为:< / p>
(= (strcase (vla-get-tagstring upc_att)) "P_TAG1")
为了为您提供此任务的替代方案,您可以使用我的ObjectDBX Wrapper功能,该功能提供了一种方法来评估另一个图纸或一组图纸上的给定功能,而无需在AutoCAD编辑器中打开此类图纸
我会亲自用以下方式编写代码:
(defun c:test ( )
(LM:DBXAttChange
"D:\\6. R&D\\Delet Group LispDBXapi\\7-EU-FE-48-AC-CIOC-SA - Copy.dwg"
'(("P_TAG1" . "555"))
)
(princ)
)
(defun LM:DBXAttChange ( dwg lst / doc flg val )
(if (setq doc (LM:GetDocumentObject dwg))
(progn
(vlax-for lyt (vla-get-layouts doc)
(vlax-for obj (vla-get-block lyt)
(if (and (= "AcDbBlockReference" (vla-get-objectname obj))
(= :vlax-true (vla-get-hasattributes obj))
)
(foreach att (vlax-invoke obj 'getattributes)
(if (and (setq val (cdr (assoc (strcase (vla-get-tagstring att)) lst)))
(vlax-write-enabled-p att)
)
(progn
(vla-put-textstring att val)
(setq flg t)
)
)
)
)
)
)
(if flg (vla-saveas doc dwg))
(vlax-release-object doc)
flg
)
(prompt (strcat "\nThe drawing \"" dwg "\" was not found or could not be accessed."))
)
)
;; Get Document Object - Lee Mac
;; Retrieves the VLA Document Object for the supplied filename.
;; The Document Object may be present in the Documents collection, or obtained through ObjectDBX.
;; It is the callers responsibility to release such object.
(defun LM:GetDocumentObject ( dwg / app dbx dwl err vrs )
(cond
( (not (setq dwg (findfile dwg))) nil)
( (cdr
(assoc (strcase dwg)
(vlax-for doc (vla-get-documents (setq app (vlax-get-acad-object)))
(setq dwl (cons (cons (strcase (vla-get-fullname doc)) doc) dwl))
)
)
)
)
( (progn
(setq dbx
(vl-catch-all-apply 'vla-getinterfaceobject
(list app
(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.")
)
( (vl-catch-all-error-p (setq err (vl-catch-all-apply 'vla-open (list dbx dwg))))
(prompt (strcat "\n" (vl-catch-all-error-message err)))
)
( dbx )
)
)
(vl-load-com) (princ)