乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 76|回复: 5

[编程交流] Putting DXF's codes in, A

[复制链接]

1

主题

4

帖子

3

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 17:08:54 | 显示全部楼层 |阅读模式
I´ve made a little function for changing easily attributes in entities
It goes like this
 
(defun atribsubst (valorcambiado grupocodigo nombreobjeto)
(entmod
(subst
(cons grupocodigo valorcambiado)
(assoc grupocodigo (entget nombreobjeto))
(entget nombreobjeto)
)
)
)
 
Works pretty well  , but for dxf group codes which are on default (for which there's no entry in entities atribute's list to be SUBStituted doesn´t work.  
 
So I added one fix with IF function...
 
(defun atribsubst2 (valorcambiado grupocodigo nombreobjeto)   
  (entmod
    (if (not (assoc grupocodigo (entget nombreobjeto)))
;;;so if there are no entry I add it
        (cons (cons grupocodigo valorcambiado)
              (entget nombreobjeto))
;;;otherwise It works with same routine
        (subst                                                        
              (cons grupocodigo valorcambiado)                           
                    (assoc grupocodigo (entget nombreobjeto))                  
                    (entget nombreobjeto))                                      
    )
  )
)
Which seem to work, no error, return the list. But after that, nothing changes...  
 
I´ve used it to change color (dxf code 62) to red (n 1) of one poly wich was on "bylayer" (default, so there's no entry in its atrib list)
(atribsubst2 1 62 (car (entsel)))
 
It returns
((62 . 1) (-1 . ) (0 . "LWPOLYLINE") (330 . ) (5 . "1B0") (100 . "AcDbEntity") so on...
 
But no color change, and doing
(entget (car (entsel)))
on same object returns
(-1 . ) (0 . "LWPOLYLINE") (330 . ) (5 . "1B0") (100 . "AcDbEntity") so on...
 
:?
 
What am I doing wrong? I´m using acad 2008 :wink:
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 17:25:57 | 显示全部楼层
have you included the following code in your LISP:
 
  1. (defun c:colourtest (/ ent1)     (setq ent1 (entget (car (entsel))))     (if (assoc 62 ent1)         (setq ent1 (subst (cons 62 1) (assoc 62 ent1) ent1))         (setq ent1 (cons (cons 62 1) ent1))     ) ;  end if     [color=Red][b](entmod ent1)[/b][/color]     (princ))
回复

使用道具 举报

1

主题

4

帖子

3

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 17:39:18 | 显示全部楼层
Yes, Check it, "entmod" it's just before the "if" function, so I don't have to write it two times  it works with the "if"output case.
 
I'm checking if your code works on my ACAD2008...
I'll let you know instantly
回复

使用道具 举报

1

主题

4

帖子

3

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 17:45:37 | 显示全部楼层
Aha, it doesn´t work neither.
 
Guess it´s supossed to change the enitity color to red, even if it was set on "bylayer", but in this case doesn´t work.
 
Maybe it needs to have its right position on atrib list? I mean in acad 2008...?
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 18:06:46 | 显示全部楼层
ahh, sorry Arka - didnt spot the "entmod" in there.
 
All I can think is that it must be an ACAD 08 thing, because the LISP I posted works fine on ACAD 04.
回复

使用道具 举报

1

主题

4

帖子

3

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 18:18:35 | 显示全部楼层
Yeah, I think so, it's one of the many advantages of having a too recent version...
Anyway, just for confirmation purposes... anybody can test the code "colortest" on an entity with color "bylayer" and running autocad 2008?
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 16:21 , Processed in 0.380332 second(s), 64 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表