乐筑天下

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

[编程交流] Create two lists of strings, a

[复制链接]

77

主题

298

帖子

232

银币

后起之秀

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

铜币
394
发表于 2022-7-5 18:36:16 | 显示全部楼层 |阅读模式
Hi guys,
 
I'm just in the very early stages of building a new LISP tool, so I'm not really sure of the best method to achieve the end result.
 
The plan is to have a LISP routine that will read data from different ProSteel elements and create a list of this data, then advise the user of the differences between the two lists.
 
For example, in a ProSteel 2D drawing, there will be 'steel' elements and 'part flag' elements.  The 'steel' and 'part flag' elements both have a part number assigned to them.  I would like to build a list of 'steel' part numbers & 'part flag' part numbers and compare them.  Any 'steel' part numbers that are missing from the list of 'part flag' part numbers, will be returned to the user, and noted as missing from the drawing.  I hope that explanation makes sense.
 
So to the code, I have routines that will read the part number data from the 'steel' & 'part flag' elements (and return strings) but I'm not sure how to build these strings into lists, and then compare them.
 
  1. (prompt "\nSelect ELEMENTS:")(setq ss (ssget '((0 . "KS*"))))(setq numtot (sslength ss))(setq con 0)(repeat numtot  (setq ent3A (ssname ss con))(setq ent3B ent3A)(setq acadapp (vlax-get-acad-object))(setq shapeinfo (vla-getinterfaceobject acadapp "PSCOMWRAPPER.Ks_ComShapeInfo"))    (vlax-invoke-method shapeinfo 'setobject  (vlax-ename->vla-object ent3A))(vlax-invoke-method shapeinfo 'getinfo)(setq shapeinfo (vla-getinterfaceobject acadApp "PSCOMWRAPPER.Ks_ComShape"))(setq shapeinfo (vlax-ename->vla-object ent3B))(setq PSptype (vlax-get-property shapeinfo 'ObjectName))  ;Part Type(setq PSpos (vlax-get-property shapeinfo 'PosNumber))  ;Part Number[color=red][b][i]if PSptype = steel, add PSpos to 'Steel List'if PSptype = partflag, add PSpos to 'Part Flag List'[/i][/b][/color] (vlax-release-object shapeinfo)   (setq shapeinfo nil)(setq acadApp nil)(princ)(setq con (1+ con)))[color=red][b][i]Check 'Part Flag List' against 'Steel List', if entries exist in 'Steel List' but not in 'Part Flag List' > Alert 'missing entries'.[/i][/b][/color]
 
I've added red text showing where I think I should add the extra functions, but I really don't know what I need to do.
 
I also am unsure if the method that I have conceived is, in fact, the best method to get this done.  So any advice or suggestions are welcome.
 
Any assistance is greatly appreciated.
 
Thanks a lot.
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 19:16:57 | 显示全部楼层
A couple of suggestions use shapeinfo1 and shapeinfo2 and declare their interface at start . use a CONS to make list.
 
This is untested
  1. (setq acadapp (vlax-get-acad-object))(setq shapeinfo1 (vla-getinterfaceobject acadapp "PSCOMWRAPPER.Ks_ComShapeInfo"))(setq shapeinfo2 (vla-getinterfaceobject acadApp "PSCOMWRAPPER.Ks_ComShape"))(prompt "\nSelect ELEMENTS:")(setq ss (ssget '((0 . "KS*"))))(setq numtot (sslength ss))(setq con 0)(repeat numtot  (setq ent3A (ssname ss con))(setq ent3B ent3A)   (vlax-invoke-method shapeinfo1 'setobject  (vlax-ename->vla-object ent3A))(vlax-invoke-method shapeinfo1 'getinfo)(setq shapeinfo2 (vlax-ename->vla-object ent3B))(setq PSptype (vlax-get-property shapeinfo2 'ObjectName))  ;Part Type(setq PSpos (vlax-get-property shapeinfo2 'PosNumber))  ;Part Number;if PSptype = steel, add PSpos to 'Steel List';if PSptype = partflag, add PSpos to 'Part Flag List'(if (= psptype "steel")(setq steellist (cons PSpos steellist))) (if (= psptype "partflag")(setq partflag (cons PSpos partflaglst)));(vlax-release-object shapeinfo)   ;(setq shapeinfo nil);(setq acadApp nil)(princ)(setq con (1+ con)))(vlax-release-object shapeinfo1)(vlax-release-object shapeinfo2)   (setq num (length steellist)(setq num2 (length partflaglist)(setq x num)(setq y num2)(repeat Num(setq stl (nth (setq x (- x 1)))) ; returns items in 1st list(while (/= num2 y)(setq part (nth (setq y (- y 1)))) ; returns items in 2nd list(if (= part stl)(princ (strcat "Found " part " " stl))(setq y num2)))   
回复

使用道具 举报

77

主题

298

帖子

232

银币

后起之秀

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

铜币
394
发表于 2022-7-5 20:04:10 | 显示全部楼层
Awesome, thanks for the reply BigAl.
 
I've used a combination of your suggestions mixed with some of Lee Mac's functions.
 
  1. (defun LM:lst->str ( lst del )    (if (cdr lst)
  2.         (strcat (car lst) del (LM:lst->str (cdr lst) del))
  3.         (car lst)
  4.     )
  5. )
  6.  
  7.  
  8. (defun LM:ListDifference ( l1 l2 )
  9.   (if l1
  10.     (if (member (car l1) l2)
  11.       (LM:ListDifference (cdr l1) l2)
  12.       (cons (car l1) (LM:ListDifference (cdr l1) l2))
  13.     )
  14.   )
  15. )
  16.  
  17.  
  18. ;; Unique  -  Lee Mac
  19. ;; Returns a list with duplicate elements removed.
  20.  
  21. (defun LM:Unique ( l / x r )
  22.     (while l
  23.         (setq x (car l)
  24.               l (vl-remove x (cdr l))
  25.               r (cons x r)
  26.         )
  27.     )
  28.     (reverse r)
  29. )
  30.  
  31.  
  32.  
  33.  
  34. ;;--------------------=={ String Subst }==--------------------;;
  35. ;;                                                            ;;
  36. ;;  Substitutes a string for all occurrences of another       ;;
  37. ;;  string within a string.                                   ;;
  38. ;;------------------------------------------------------------;;
  39. ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
  40. ;;------------------------------------------------------------;;
  41. ;;  Arguments:                                                ;;
  42. ;;  new - string to be substituted for 'old'                  ;;
  43. ;;  old - string to be replaced                               ;;
  44. ;;  str - the string to be searched                           ;;
  45. ;;------------------------------------------------------------;;
  46. ;;  Returns:  String with 'old' replaced with 'new'           ;;
  47. ;;------------------------------------------------------------;;
  48.  
  49. (defun LM:StringSubst ( new old str / inc len )
  50.     (setq len (strlen new)
  51.           inc 0
  52.     )
  53.     (while (setq inc (vl-string-search old str inc))
  54.         (setq str (vl-string-subst new old str inc)
  55.               inc (+ inc len)
  56.         )
  57.     )
  58.     str
  59. )
  60.  
  61.  
  62.  
  63.  
  64.  
  65. (defun C[emoji14]spfc ( / steellist partflaglst)
  66.  
  67. (vl-load-com)
  68.  
  69. (setq acadapp (vlax-get-acad-object))
  70. (setq shapeinfo1 (vla-getinterfaceobject acadapp "PSCOMWRAPPER.Ks_ComShapeInfo"))
  71. (setq shapeinfo2 (vla-getinterfaceobject acadApp "PSCOMWRAPPER.Ks_ComShape"))
  72.  
  73. (prompt "\nSelect ELEMENTS:")
  74. (setq ss (ssget '((0 . "KS*"))))
  75.  
  76. (setq numtot (sslength ss))
  77.  
  78. (setq con 0)
  79. (repeat numtot  
  80. (setq ent3A (ssname ss con))
  81. (setq ent3B ent3A)
  82.  
  83.  
  84. (vlax-invoke-method shapeinfo1 'setobject  (vlax-ename->vla-object ent3A))
  85. (vlax-invoke-method shapeinfo1 'getinfo)
  86.  
  87. (setq shapeinfo2 (vlax-ename->vla-object ent3B))
  88.  
  89. (setq PSON (vlax-get-property shapeinfo2 'ObjectName))  ;Part Type
  90. (setq PSpos (vlax-get-property shapeinfo2 'PosNumber))  ;Part Number
  91.  
  92. (cond
  93. ((eq (strcase PSON) "KS_SHAPE") (setq steellist (cons PSpos steellist)))
  94. ((eq (strcase PSON) "KS_BENDSHAPE") (setq steellist (cons PSpos steellist)))
  95. ((eq (strcase PSON) "KS_ARCSHAPE") (setq steellist (cons PSpos steellist)))
  96. ((eq (strcase PSON) "KS_PLATE") (setq steellist (cons PSpos steellist)))
  97. ((eq (strcase PSON) "KS_BENDPLATE") (setq steellist (cons PSpos steellist)))
  98. ((eq (strcase PSON) "KS_ARCPLATE") (setq steellist (cons PSpos steellist)))
  99. ((eq (strcase PSON) "KS_POSFLAG") (setq partflaglst (cons PSpos partflaglst)))
  100. )
  101.  
  102. (setq con (1+ con))
  103. )
  104.  
  105. (vlax-release-object shapeinfo1)
  106. (vlax-release-object shapeinfo2)
  107.  
  108. (if (null steellist)
  109. (progn (princ "\nNo Steel Selected...") (vl-exit-with-error ""))
  110. )
  111.  
  112. (if (null partflaglst)
  113. (progn (princ "\nNo Position Flags Selected...") (vl-exit-with-error ""))
  114. )
  115.  
  116. (setq steellist (LM:Unique steellist))
  117. (setq partflaglst (LM:Unique partflaglst))
  118.  
  119. (setq steellist (vl-sort steellist '
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-12 13:45 , Processed in 0.684356 second(s), 58 queries .

© 2020-2025 乐筑天下

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