ksperopoulos 发表于 2022-7-6 00:10:26

听起来我仍然需要使用第n个函数来检索所需的结果,对吗?massoc只会将我的所有选项减少到300个点对,这样我就不会在300组之外错误地选择一个错误的选项?

cwake 发表于 2022-7-6 00:12:37

对假设数据是恒定的,并且总是以相同的顺序。在您第一次发布的示例中,我看不到任何其他方式来区分它。

ksperopoulos 发表于 2022-7-6 00:17:14

好啊非常感谢。我只是想确保我理解正确。所以massoc是一个子函数,它可以在代码中的任何地方,或者它是否需要位于我需要在程序中使用它的地方?

cwake 发表于 2022-7-6 00:19:20

将其作为子函数放在代码中的任何位置。然后用你的assoc列表(massoc4 300(entget ename))调用它。

ksperopoulos 发表于 2022-7-6 00:23:05

每次使用时,我都会收到此错误消息。这会影响我的其余代码吗?
 
错误:错误的参数类型:consp“90 LR”
 
编辑:Nevermind。我试着使用(cdr(nth 4(massoc4 300 elist)))。我想cdr函数已经在massoc子函数中使用了,所以在代码的其他部分中不再需要它。谢谢大家的帮助!
 
顺便问一下,massoc4末尾的4有什么意义吗?我可以用massoc吗?

cwake 发表于 2022-7-6 00:26:03

接得好。我的措辞可能在这方面误导了你,因为我没有查看返回列表的结构。很抱歉
至于函数名,您可以将其命名为massoc,只要确保如果您使用了像MASSOC4这样的递归函数,您也可以将其自身调用的位置重命名。希望这有意义?

ksperopoulos 发表于 2022-7-6 00:29:02

是的,这很有道理。谢谢

ksperopoulos 发表于 2022-7-6 00:31:15

好的,这里有一个不同的场景,但仍然围绕着同一个主题。我有使用带有属性的块的多重引线。我试图获得这些属性的价值。从帮助文件中,多重引线“块属性文本字符串”的DXF代码为302。当你在一个多重引线上运行(entget(car(entsel)),有两个302值。第一个302值是(302。“LEADER{”),而第二个302值是我真正想要的。我可以使用相同的massoc子函数来提取值,但我认为有一种更好的方法,你们中一些经验更丰富的程序员可以向我指出。

cwake 发表于 2022-7-6 00:34:55

这就是我一直在做的。它再次使用了member和assoc的组合。我假设您只想提取文本字符串,而不是替换它?因为如果你想替换它,我通常在同一个while循环中提取对象ID。
 

;get the attributes for the block
(setq tmp1 (member (assoc 344 elist) elist)) ;cut out the irrelevant (and duplicated car) earlier codes
(while (setq tmp1 (member (assoc 330 tmp1) tmp1))
(setq attdata (cons (list (cdr (assoc 177 tmp1)) ;attribute number - this becomes important if the text has fields in it
                            (cdr (assoc 302 tmp1)) ;the attribute string itself
                            (= (cdr (assoc 101 (entget (cdr (assoc 330 tmp1))))) "Embedded Object") ;single or multiline attribute - this becomes important if you want to know which formatting strings might be present
                            )
                      attdata
                      )
      tmp1 (cdr tmp1)
      )
);while
;if attributes
(if attdata
....process them
    )

cwake 发表于 2022-7-6 00:39:16

我应该补充一点,上面的代码是为在多重引线块中可能有多个属性而编写的。它只适用于一个属性,但也适用于100个属性。如果你知道你只对其中一个感兴趣,你可以把它简化为。
 
(cdr (assoc 302 (member (assoc 344 elist) elist)))
页: 1 [2]
查看完整版本: 指定特定DXF Co