乐筑天下

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

[编程交流] Check if a profile exist, copy

[复制链接]

1

主题

8

帖子

7

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 06:39:17 | 显示全部楼层 |阅读模式
Hi!
 
I am trying to figure out how to make a lisp that does the following:
 
1. Check if a profile with a given name (eg. Engineering) exist in AutoCAD
2. If the profile exist it should be set active
3. If the profile does not exist the active profile should be copied and named "Engineering" and set active.
 
I have tried to put together some code from several sites and I have this:
 
  1. (vl-load-com);get profiles from AutoCAD(vlax-invoke-method acadProfiles 'GetAllProfileNames 'profilelist);convert the list(setq profilelist (vlax-safearray->list profilelist));check if the profile exist(if (not (member "Engineering" profilelist));if it does'n exist(progn   ;copy active profile and rename to "Engineering"  (vlax-invoke-method acadProfiles 'CopyProfile actProfile "Engineering") ));set "Engineering" as active profile(vla-put-ActiveProfile acadProfiles "Engineering")
 
BUT, it doesn't work.
 
Can anyone help me out?
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-6 06:43:26 | 显示全部楼层
Welcome to CadTutor
 
Hope this would help you with it .
 
  1. (defun c:Test (/ Pfs lst) ;;--- Tharwat 25. April. 2013 ---;; (setq Pfs (vla-get-Profiles             (vla-get-Preferences (vlax-get-acad-object))           ) ) (vla-GetAllProfileNames Pfs 'lst) (if (not       (member "Engineering" (vlax-safearray->list lst))     )   (progn     (vla-copyprofile       Pfs       (vla-get-activeprofile Pfs)       "Engineering"     )     (vla-put-activeprofile Pfs "Engineering")   )   (vla-put-activeprofile Pfs "Engineering") ) (princ))(vl-load-com)
回复

使用道具 举报

1

主题

8

帖子

7

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 06:46:24 | 显示全部楼层
Thank you for your fast reply. But I couldn't get it to work. There are no errors in AutoCAD but it doesn't copy the current profile (which is "Unnamed Profile").
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-6 06:49:26 | 显示全部楼层
Actually it should do , did you check the profiles tab in the options ?
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 06:53:24 | 显示全部楼层
Try this:
  1. (defun c:setprofile ( / lst prf prn )   (setq prn "Engineering"         prf (vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))   )   (vla-getallprofilenames prf 'lst)   (setq lst (vlax-safearray->list lst))   (if (member prn lst)       (vla-put-activeprofile prf prn)       (progn           (vla-copyprofile prf (getvar 'cprofile) prn)           (vla-put-activeprofile prf prn)       )   )   (princ))(vl-load-com) (princ)
 
I wouldn't assume that the current profile will always be first in the list returned by the getallprofilenames method.
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-6 06:56:22 | 显示全部楼层
Lee , May I know what's the new with your code to mine ?
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 06:58:57 | 显示全部楼层
 
If I may... Consider the difference between (car nm), and (getvar 'cprofile), in the context of Lee's ending comment.
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-6 07:02:42 | 显示全部楼层
 
However if the Auto-Cad session has only one profile or more the (car nm) would return a name of a profile and would copy one
of them and activate it as it's been asked by the OP .
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:06:47 | 显示全部楼层
 
But the OP states:
 
Hence my comment:
回复

使用道具 举报

1

主题

8

帖子

7

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 07:10:24 | 显示全部楼层
 
Checked in the profiles tab but there is only Unnamed profile that is listed. I have also tried it after adding other profiles but nothing seams to happen.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 14:47 , Processed in 0.720932 second(s), 72 queries .

© 2020-2025 乐筑天下

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