乐筑天下

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

[编程交流] 检查GetString是否存在

[复制链接]

10

主题

40

帖子

31

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
50
发表于 2022-7-5 20:58:10 | 显示全部楼层
是的,你是对的,你的独立代码可以工作(忘了独立测试),当我把它插入我的程序时,它第二次崩溃了。。。。六羟甲基三聚氰胺六甲醚。
需要找出是什么原因造成的,因为没有桌子部分它不会崩溃。
回复

使用道具 举报

10

主题

40

帖子

31

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
50
发表于 2022-7-5 21:03:05 | 显示全部楼层
我解决了问题,但没有找到答案。
在创建表格之前,将创建一个Table_样式。
此代码(试用和错误构建)导致错误。
它还应该检查table_样式是否已经存在,但在某个地方崩溃了
第二次调用子函数。
 
  1. (defun CTS (/ acmcol adoc clsname keyname newstyleobj tbldict tblstylename)
  2. ;(vl-load-com)
  3. (or adoc
  4.         (setq adoc
  5.                 (vla-get-activedocument
  6.                         (vlax-get-acad-object)
  7.                 )
  8.         )
  9. )
  10. (setq        tbldict
  11.         (vla-item
  12.                 (vla-get-dictionaries
  13.                         (vla-get-database adoc)
  14.                 )
  15.                 "Acad_TableStyle"
  16.         )
  17. )
  18. ;; look in the tablestyle dictionary to search for our style name:
  19. (if
  20.         (vl-catch-all-error-p
  21.                 (setq tbstyleObj
  22.                         (vl-catch-all-apply
  23.                                 (function (lambda() (vla-item tbldict "Anchor Table")))
  24.                         )
  25.                 )
  26.         )
  27.            ;; if table style "TblStyleName" does not exist:
  28.         (progn
  29.                 (setq keyname "NewStyle"
  30.                                         clsname "AcDbTableStyle"
  31.                                         tblstylename "Anchor Table"
  32.                 )
  33.                 (setq        newstyleobj
  34.                                 (vlax-invoke tbldict 'Addobject keyname clsname)
  35.                 )
  36.                 (setq acmcol (vla-GetInterfaceObject
  37.                                                         (vlax-get-acad-object)
  38.                                                         (strcat "AutoCAD.AcCmColor." (itoa (atoi(getvar "acadver"))))
  39.                                                  )
  40.                 )
  41.                 (vlax-put acmcol 'Colorindex 254)
  42.                 (vlax-put newstyleobj 'Name TblStyleName)
  43.                 (vlax-put newstyleobj 'Description "Anchor Table")
  44.                 (vlax-put newstyleobj 'HorzCellMargin 0.25)
  45.                 (vlax-put newstyleobj 'VertCellMargin 0.25)
  46.                 (vlax-put newstyleobj 'TitleSuppressed :vlax-false)
  47.                 (vlax-put newstyleobj 'HeaderSuppressed :vlax-false)
  48.                 (vlax-invoke newstyleobj 'SetBackgroundColor acTitleRow acmcol)
  49.                 (vlax-invoke newstyleobj 'SetBackgroundColorNone acDataRow :vlax-false)
  50.                 (vlax-invoke newstyleobj 'SetGridLineWeight acHorzBottom acTitleRow acLnWt035)
  51.                 (vlax-invoke newstyleobj 'SetTextStyle (+ acHeaderRow acTitleRow) "Arial-B")
  52.                 (vlax-invoke newstyleobj 'SetTextStyle acDataRow "Arial")
  53.                 (vlax-invoke newstyleobj 'SetTextHeight acTitleRow 2.5)                       
  54.                 (vlax-invoke newstyleobj 'SetTextHeight (+ acDataRow acHeaderRow) 1.5)
  55.                 (vlax-invoke newstyleobj 'SetGridVisibility acHorzInside  (+ acDataRow acHeaderRow) :vlax-true)
  56.                 (vlax-invoke newstyleobj 'SetAlignment (+ acDataRow acTitleRow) acMiddleCenter)
  57.                 (vlax-invoke newstyleobj 'SetAlignment acHeaderRow acMiddleCenter)
  58.         )
  59.            ;;inform user if style exist:
  60.            (princ (strcat "\nStyle "" tblstylename "" already exist."))
  61.   )
  62.   (setvar "ctablestyle" "Anchor Table")
  63. (princ)
  64. )

 
在创建表之前调用该函数:
 
  1. (defun c:test ( / lay lst obj )
  2. (vl-load-com)
  3. (CTS)
  4. (setq lst (mapcar 'strcase (layoutlist)))
  5. (while
  6.         (and (/= "" (setq lay (getstring t "\nEnter layout for table: ")))
  7.                 (or
  8.                         (and
  9.                                 (not (member (strcase lay) lst))
  10.                                         (princ (strcat "\nLayout "" lay "" doesn't exist."))
  11.                                 )
  12.                         (and
  13.                                 (setq sel (ssget "_X" (list '(0 . "ACAD_TABLE") '(8 . "29-anchor wires-#*") (cons 410 lay))))
  14.                                 (princ
  15.                                         (strcat
  16.                                                 "\nA table already exists on layer ""
  17.                                                 (cdr (assoc 8 (entget (ssname sel 0))))
  18.                                                 "" in layout "" lay ""."
  19.                                         )
  20.                                 )
  21.                         )
  22.                 )
  23.         )
  24. )
  25.                        
  26.    (if (/= "" lay)
  27.        (progn
  28.            (setq objtable
  29.                (vla-addtable
  30.                    (vla-get-block (vla-item (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) lay))
  31.                    (vlax-3D-point 312 289)
  32.                    11 10 4.652 9.356
  33.                )
  34.            )
  35.            (foreach col '(6 7 8 9)
  36.                (vla-setcelltextheight objtable 1 col 1.25)
  37.            )
  38.                 (vla-settext objtable 0 0 "STINGRAY ANCHORS")
  39.                 (vla-settext objtable 1 1 "EASTING")
  40.                 (vla-settext objtable 1 3 "NORTHING")
  41.                 (vla-settext objtable 1 5 "ANGLE")
  42.                 (vla-settext objtable 1 6 "LENGTH ANCHORE WIRE")
  43.                 (vla-settext objtable 1 7 "MIDLINE BUOY 1 *")
  44.                 (vla-settext objtable 1 8 "MIDLINE BUOY 2 *")
  45.                 (vla-settext objtable 1 9 "MIDLINE BUOY 3 *")
  46.                 (vla-MergeCells objtable 1 1 1 2)
  47.                 (vla-MergeCells objtable 1 1 3 4)
  48.                 (vla-put-HorzCellMargin objtable 0.25)
  49.                 (vla-put-VertCellMargin objtable 0.25)  
  50.                 (vla-setrowheight objtable 1 10)
  51.                 (vla-setcolumnwidth objtable 0 15.182); 0 is first column
  52.                 (vla-setcolumnwidth objtable 1 4.756)
  53.                 (vla-setcolumnwidth objtable 2 13.956)
  54.                 (vla-setcolumnwidth objtable 3 4.756)
  55.                 (vla-setcolumnwidth objtable 4 13.956)
  56.                 (vla-setcolumnwidth objtable 5 9.969)
  57.                 (foreach col '(6 7 8 9)
  58.                         (vla-setcolumnwidth objtable col 9.356)
  59.            )
  60.        )
  61. )
  62. (princ)
  63. )
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-12 01:01 , Processed in 0.450400 second(s), 54 queries .

© 2020-2025 乐筑天下

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