Lee Mac 发表于 2022-7-6 11:52:26

Cary Hulse项目

感谢大家对我的积分经理计划Cary的兴趣,我意识到它并不能完全满足您的需求,所以希望这能满足您的需求
 
新年快乐!
 

chulse 发表于 2022-7-6 11:56:42

李,太棒了,谢谢!
我今天要玩它(回去工作)
我正在重新构建我的主模板,所以它来得正是时候

Lee Mac 发表于 2022-7-6 12:00:17

嗯,我忍不住。。。
 
让我知道你进展如何!

chulse 发表于 2022-7-6 12:02:35

如果你有时间的话,我可以请你像上次那样给我评论一下吗?

Lee Mac 发表于 2022-7-6 12:06:41

这就是我的全部时间:
 

(defun c:attpop (/ *error* StrBrk               

                  ALST ATT BNME DDEL DOC FILE LST NL OBJ OFILE PT SPC UFLAG X Y )

;; by Lee Mac ~ 01.01.10

;; --{ Commented Version }--

(vl-load-com) ;; Load Visual LISP Console


;; --{Error Handler Function}--

(defun *error* (msg);; Localised with variables
   
   (and ofile (close ofile)) ;; If ofile still non-nil, close the open file
   
   (and uflag (vla-EndUndoMark doc));; If uflag still non-nil, End the Undo Mark.
   
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*");; Suppress Cancel messages
      
       (princ (strcat "\n** Error: " msg " **"))) ;; Print fatal errors
   
   (princ))

;; -----------------------------------------------


;; --{StrBrk Function}--

;; By Lee Mac~Used to break a string into a list of elements,
;;                using a delimiter.

(defun StrBrk (str chrc / pos lst)
   (while (setq pos (vl-string-position chrc str))
   (setq lst (cons (substr str 1 pos) lst)
         str (substr str (+ pos 2))))
   (reverse (cons str lst)))

;; -----------------------------------------------


(if (and
       ;; Block selection

       (setq bNme (getfiled "Select Block to Insert" (cond (*block_file*) ("")) "dwg"   16))

       ;; Data File Selection
       (setq file (getfiled "Select Input File"      (cond (*load_file*)("")) "txt;csv" 16)))
   
   (progn

   ;; Start the Undo Mark before we proceed uflag = T
   
   (setq uflag (not (vla-StartUndoMark
                        (setq doc (vla-get-ActiveDocument
                                    (vlax-get-acad-object)))))

         ;; Get the Active Space

         spc (if (zerop (vla-get-activespace doc))
               (if (= (vla-get-mspace doc) :vlax-true)
                   (vla-get-modelspace doc)
                   (vla-get-paperspace doc))
               (vla-get-modelspace doc)))

   ;; Get the correct delimiter, if CSV, comma, else space.
   
   (setq dDel (if (eq ".CSV" (vl-filename-extension file)) 44 32)

         ;; Save the defaults for next time, and open the file, ofile = non-nil
         
         *block_file* bNme *load_file* file ofile (open file "r"))

   ;; Read the file and break the strings

   (while (setq nl (read-line ofile))
       (setq lst (cons (StrBrk nl dDel) lst)))

   ;; Close the file, ofile = niland reverse the lst.
   
   (setq ofile (close ofile) lst (reverse lst))

   ;; While there are attribs in the list, AND the user has clicked a point

   (while (and (setq x(car lst))
               (setq pt (getpoint "\nSpecify Point for Block: ")))

       ;; Catch any errors that occur when inserting the block
      
       (if (vl-catch-all-error-p
             (setq obj
               (vl-catch-all-apply (function vla-InsertBlock)
               (list spc (vlax-3D-point pt) bNme 1. 1. 1. 0.))))
         
         (princ "\n** Error Inserting Block **")

         ;; Else populate the Attribs using the values in the list.
         (progn

         ;; Get a list of VLA-objects (attribs)
         (setq aLst (vlax-invoke obj 'GetAttributes))

         ;; While there is an attrib and value
         (while (and (setq y   (car x))
                     (setq att (car aLst)))
            
             ;; Populate the attribs
             (vla-put-TextString att y)
             (setq x (cdr x) aLst (cdr aLst)))))

       ;; Move onto next item
       (setq lst (cdr lst)))

   ;; End the Undo Mark,uFlag = nil

   (setq uFlag (vla-EndUndoMark doc))))

;; Clean exit
(princ))


 
希望这有点帮助。

chulse 发表于 2022-7-6 12:09:19

我相信会的,谢谢!

chulse 发表于 2022-7-6 12:14:17

好的,你激励了我,让我更进一步。我找到了一些用于填充动态属性的函数,我正在尝试将它们添加到您的代码中。这对我来说是一个很好的开始,我自己都做不到。
 
不过,首先,我已经更改了您的代码,使其不需要块,而只需要使用我需要的块(它始终是相同的)。
 
我的问题是:我的块只有一个属性,但有3个动态(线性)属性。目前,当我添加块时,它用列表中由逗号分隔的所有值填充one属性。这是它的初衷吗?
我想尝试的是将该列表分解为只获取一个属性的第一个值,然后将剩余值用于其他函数?
 
我将张贴我在这里有一点。。。
再次感谢您的大力帮助!

Lee Mac 发表于 2022-7-6 12:16:09

 
沃泽。。。谢谢你注意我的打字错误!比较文件扩展名时缺少strcase。我已经更新了第一个帖子。
 
我会尽我所能帮助Cary,但我警告你,我没有使用动态块的经验。。。

chulse 发表于 2022-7-6 12:19:56

好吧,我想我有点进展了。。。
 
你能帮我确保我理解这个过程/把事情按正确的顺序安排好吗?
我想这就是我遇到的问题。。。
完整代码随附。
 
(progn
         ;; Get a list of VLA-objects (attribs)
         (setq aLst (vlax-invoke obj 'GetAttributes)) ;;Can I assign this to the attribute tag "TREE#"?
         ;; While there is an attrib and value
         (while (and (setq TRNUM   (car x))
                     (setq att (car aLst))
;;;set variables for dynamic values, not sure if this is in the correct place?
(setq CANOP (cadr x))
(setq CRZ (caddr x))
(setq CRD (cadddr x))
);end and
            
             ;; Populate the attribs
             (vla-put-TextString att TRNUM)
             ;;(setq x (cdr x) aLst (cdr aLst));;;edited by CH - only one attribute in block
      
;;;Set Dynamic Properties using "myModifyBk" function
(myModifyBk (list "CRD Radius" CRD))
(myModifyBk (list "CRZ Radius" CRZ))
(myModifyBk (list "Canopy Radius" CANOP))
   
);end while
);end progn
树lsp

chulse 发表于 2022-7-6 12:22:38

我会在这里更改什么(假设这是正确的位置)以在对话框中默认为CSV?
 
(setq file (getfiled "Select Input File"      (cond (*load_file*)("")) "txt;csv" 16)))
页: [1] 2
查看完整版本: Cary Hulse项目