Lee Mac 发表于 2022-7-5 16:12:19

 
我以为这已经解决了。。。?
(vla get block lay\t)
 
编辑:你是对的,我从未意识到这条线会穿过所有物体。。对象管理组织
 
原因是我不知道如何使用匿名名称处理块
[*U12*]并通过ssget过滤器检索有效名称。除了搜索块表(教学..教学…)之外,还有其他方法吗
 
 
这个怎么样。。。
 

(defun c:GrabTBValue (/ dwg sum ths_blk cnt func strVal)
(defun Tag_value (tagname / lay_t attr tag )
(vlax-for lay_t (vla-get-layouts dwg)
(vlax-for p (vla-get-block lay_t)
(if (and
(= (vla-get-objectname p) "AcDbBlockReference")
(= (strcase (vla-get-effectivename p)) (strcase ths_blk)))
(if (and (= (vla-get-hasattributes p) :vlax-true)
   (safearray-value (setq attr (vlax-variant-value (vla-getattributes p)
            )
    )
   )
)   
   (foreach tag (vlax-safearray->list attr)
   (if (= (strcase tagname) (strcase (vla-get-tagstring tag)))
   (setq strVal (vla-get-TextString tag))
      ))
   )
)
)
)
)

(setq dwg (vla-get-activedocument (vlax-get-acad-object))
   sum ( vla-get-SummaryInfo dwg)
ths_blk "TITLEBLOCKA" cnt 0) ;<---your blockname
(foreach b '("title" "subject" "author" "keywords")
   (setq func (eval (read (strcat "vla-put-" b))))
         (Tag_value (strcat "TITLE-" (itoa (setq cnt (1+ cnt)))))
   (func sum strVal)
    )
)

kam1967 发表于 2022-7-5 16:14:38

在我的工作中,20岁是不够的。
我真正的问题是,我认为我们应该采用每个绘图系统1个布局,这将解决很多问题,也会解决很多性能问题,但我是唯一一个想要这样做的人。所以我现在反复强调,这幅画画得太慢了,因为它有30个布局。但是,由于使用1布局将打乱那里的工作流程(即使是临时的),它暂时不会改变。我想这也是为什么在Autocad上而不是Inventor上的原因。

pBe 发表于 2022-7-5 16:19:36

 
这是一种困难的方法,有两种基本方法:
 
1) (我的首选)
 
过滤块名称和所有匿名块:
 

(defun c:UpdateSummaryInfo ( / sum tags ss ) (vl-load-com)
;; © Lee Mac 2011

(setq sum
   (vla-get-SummaryInfo
   (vla-get-ActiveDocument (vlax-get-acad-object))
   )
)

(setq tags
'(
   ("TITLE-1" .    title)
   ("TITLE-2" .subject)
   ("TITLE-3" .   author)
   ("TITLE-4" . keywords)
   )
)

(if (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1) (2 . "TITLEBLOCK"))))
   (mapcar
   (function
       (lambda ( attrib / prop )
         (if (setq prop (cdr (assoc (strcase (vla-get-TagString attrib)) tags)))
         (vlax-put-property sum prop (vla-get-TextString attrib))
         )
       )
   )
   (vlax-invoke (vlax-ename->vla-object (ssname ss 0)) 'GetAttributes)
   )
)

(princ)
)
 
然后在对块进行操作之前,在遍历集合时使用条件来检查EffectiveName。
 
2) 使用块定义记录的块参照:
 

(defun c:GrabTBValue (/ dwg sum ths_blk objcts cnt tg_nm)
(while (< cnt 4)
(setq dwg (vla-get-activedocument (vlax-get-acad-object))
   sum ( vla-get-SummaryInfo dwg)
ths_blk "TITLEBLOCKA" CNT 0) ;<---your blockname


(if (setq objcts (ssget "_X" '((0 . "INSERT")(66 . 1))))

(vlax-for p (vla-get-activeselectionset dwg)
(if (and
   (= (vla-get-objectname p) "AcDbBlockReference")
   (= (strcase (vla-get-effectivename p)) (strcase ths_blk)))
       (if (and (= (vla-get-hasattributes p) :vlax-true)
         (safearray-value (setq attr (vlax-variant-value (vla-getattributes p)))))

         (foreach tag (vlax-safearray->list attr)
      (setq tg_nm (strcase (vla-get-tagstring tag)))
      (cond
         ((= tg_nm "TITLE-1")
      (vla-put-title sum (vla-get-TextString tag))
         (setq cnt (1+ cnt))
         )
         ((= tg_nm "TITLE-2")
      (vla-put-subject sum (vla-get-TextString tag))
         (setq cnt (1+ cnt))
         )
         ((= tg_nm "TITLE-3")
      (vla-put-author sum (vla-get-TextString tag))
         (setq cnt (1+ cnt))
         )
         ((= tg_nm "TITLE-4")
      (vla-put-keywords sum (vla-get-TextString tag))
         (setq cnt (1+ cnt))
         )
      )
          )
      )
      )
    )
)

)(princ)
)

 
然后使用(类似于此处):
 

(defun c:test ()
(setq dwg (vla-get-activedocument (vlax-get-acad-object))
   sum ( vla-get-SummaryInfo dwg))

(vla-AddCustomInfo sum "Sheet no" "Title of Sheet")
)

 
要创建ssget筛选器,请执行以下操作:
 
(ssget "_X" '((0 . "INSERT") (2 . "`*U*,TITLEBLOCK") (66 . 1)))
 
但它真的是一个6个,另一个半打。。。在第一种方法中,我们遍历图形中的所有匿名块引用,并选择我们喜欢的块引用;在第二步中,我们遍历匿名块定义(而不是引用),并选择我们喜欢的块定义。。。
 
 
不完全是这样,While是多余的,因为在迭代整个选择集之前不会对测试条件进行评估,此时可能已经找到属性,如果没有,代码将不必要地再运行3次。。。
 
但你仍然在正确的轨道上使用COND,允许你一次更新信息。
 
也许可以看看我之前的代码。
 

pBe 发表于 2022-7-5 16:22:24

谢谢李
 
至少现在只需要一次
 
顺便说一句:我喜欢使用
 

;; Returns list of the Anonymous names taken by a Dynamic Block (if any)-Lee Mac 2011-www.lee-mac.com
;; Arguments:block- name of Dynamic Block.

(defun AnonymousInstancesof ( block / def rec nme ref lst )
(while (setq def (tblnext "BLOCK" (null def)))
   (if (= 1 (logand 1 (cdr (assoc 70 def))))
   (progn
       (setq rec
         (entget
         (cdr
             (assoc 330
               (entget
               (tblobjname "BLOCK" (setq nme (cdr (assoc 2 def))))
               )
             )
         )
         )
       )
       (while (setq ref (assoc 331 rec))
         (if
         (and
             (eq block (vla-get-effectivename (vlax-ename->vla-object (cdr ref))))
             (not (member nme lst))
         )
         (setq lst (cons nme lst))
         )
         (setq rec (cdr (member (assoc 331 rec) rec)))
       )
   )
   )
)
(reverse lst)
)

 
(协会…)
 
我已经在过去几天编写的新代码中应用了这种方法

CADkitt 发表于 2022-7-5 16:24:34

嗨,李
我需要做一个非常类似的任务,工作约150图纸。我不认为你可以建议如何做到这一点,但每个标题行的连接。
我实际上要做的是映射和填充以下内容
图形摘要:标题栏
摘要:标题1,+空格,+标题2,+空格,+标题3
主题:状态
注释:版本
 
感谢您的帮助。

pBe 发表于 2022-7-5 16:27:43

CADkitt 发表于 2022-7-5 16:29:58

At my job 20 isn't enough.
My real problem is I think we should go to a 1 layout per drawing system this would fix a lot of issues also a lot performance issues, but I am the only one that want this. So I am now hammering into them that the drawing is so slow because it has 30 layouts. But since using 1 layout will disrupts there workflow (even if it is temporary) it is not gonna change for a while. I guess it is the same reason why where on Autocad and not Inventor.

Lee Mac 发表于 2022-7-5 16:33:54

 
A difficult one, two essential ways to approach it:
 
1) (My preferred choice)
 
Filter for the block name AND all anonymous blocks:
 

(ssget "_X" '((0 . "INSERT") (2 . "`*U*,TITLEBLOCK") (66 . 1)))
 
Then use a conditional when iterating through the set to check the EffectiveName before operating on the block.
 
2) Use the Block Refs of the Block Definition Record:
 

;; Returns list of the Anonymous names taken by a Dynamic Block (if any)-Lee Mac 2011-www.lee-mac.com;; Arguments:block- name of Dynamic Block.(defun AnonymousInstancesof ( block / def rec nme ref lst ) (while (setq def (tblnext "BLOCK" (null def)))   (if (= 1 (logand 1 (cdr (assoc 70 def))))   (progn       (setq rec         (entget         (cdr             (assoc 330               (entget               (tblobjname "BLOCK" (setq nme (cdr (assoc 2 def))))               )             )         )         )       )       (while (setq ref (assoc 331 rec))         (if         (and             (eq block (vla-get-effectivename (vlax-ename->vla-object (cdr ref))))             (not (member nme lst))         )         (setq lst (cons nme lst))         )         (setq rec (cdr (member (assoc 331 rec) rec)))       )   )   ) ) (reverse lst))
 
Then use something like (similar to here):
 

(defun LM:BlockList->Str ( lst del / f ) ;; © Lee Mac 2011 (defun f ( s ) (if (wcmatch s "`**") (strcat "`" s) s))(if (cdr lst)   (strcat (f (car lst)) del (LM:BlockList->Str (cdr lst) del))   (f (car lst)) ))
 
To create the ssget filter:
 

(ssget "_X" (list   (cons 0 "INSERT")   (cons 2 (LM:BlockList->Str (cons "TITLEBLOCK" (AnonymousInstancesof "TITLEBLOCK")) ","))   (cons 66 1) ))
 
But its really 6 of one, half a dozen of the other... in the first method we are iterating through all anonymous block references in the drawing and choosing those we like; in the second we iterate through the anonymous block definitions (instead of references) and choose those we like...
 
 
Not quite, the While is redundant since the test condition will not be evaluated until the entire selection set is iterated, by which point the attributes are likely found already, and if they aren't the code will run needlessly another 3 times...
 
But still you're on the right track using the COND to allow you to update the information in one pass.
 
Perhaps take a look at my earlier code.
 
Lee

pBe 发表于 2022-7-5 16:37:09

Thanks Lee
 
at least now it just one pass
 
BTW: i like theideaofusing
 

(setq tags'(   ("TITLE-1" .    title)   ("TITLE-2" .subject)   ("TITLE-3" .   author)   ("TITLE-4" . keywords)   ) )
 
(assoc ...)
 
I already applied this approach on the new codes I've written this past few days

Volleyer1 发表于 2022-7-5 16:40:13

Hi Lee
I need to do a very similar task to work on about 150 drawings. I don't suppose you could suggest how to do this but with concatenation of each title line.
What I am actually trying to do is map and populate the following
Drawing summary   :   Title block
Summary                :   Title 1, +space, +Title 2, +space, +Title 3
Subject                  :   Status
Comments               :   Version
 
Any help appreciated.
页: 1 [2]
查看完整版本: 自动填写