乐筑天下

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

[编程交流] VBA - returning individual att

[复制链接]

16

主题

43

帖子

33

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-6 22:28:40 | 显示全部楼层 |阅读模式
Hi Everyone,
 
Is someone out there able to help me with this? I am trying to create some code that allows the user to click on one attribute at a time – and each time an attribute is selected its text style resets back to its default.
 
Example – on the attached drawing:
AttributeTest.dwg
Block “CONTACT-8” on the very left side of the drawing has three attributes. The first attribute has had “75” entered. When this attribute is double clicked you can see that under the “Text Options” tab the Text Style has been adjusted. I want to click that particular attribute and have only that attribute go back to its default Text Style (STANDARD in this case.) I do NOT want any of the other attributes to be adjusted. I want only that one to be adjusted and then the user can move on to the next block containing the next attribute they choose to return to its default. I want to continue through the drawing until the user clicks enter twice to end the macro.
 
I’m not really sure how approach this. I began with the code below (which does not work), but I don’t think this is the correct approach after all because it would change all the attributes for the selected block as opposed to just the selected attribute.
 
  1. Option ExplicitPublic Sub SelectBlockAndUpdateTextStyle()Dim MyBlock As AcadBlockReferenceDim SelectedBlock As VariantDim i As VariantThisDrawing.Utility.GetEntity MyBlock, SelectedBlock, "Select object:"If MyBlock.ObjectName = "AcDbBlockReference" Then   If MyBlock.HasAttributes Then       Dim MyBlockAttribute As Variant       MyBlockAttribute = MyBlock.GetAttributes       For i = LBound(MyBlockAttribute) To UBound(MyBlockAttribute)           If Not MyBlockAttribute(i).TextStyle = "STANDARD" Then           MyBlockAttribute(i).TextStyle = "STANDARD"           End If           ThisDrawing.Application.Update       Next   End IfElse   MsgBox "You didn't select an AutoCAD block. Better luck next time."End IfEnd Sub
Is there anyone who can help me and point me in the right direction?
 
I definitely appreciate your help
 
Thank you,
Mike
回复

使用道具 举报

16

主题

43

帖子

33

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-6 22:34:58 | 显示全部楼层
Hmmm crickets again.
 
Well either I'm not good at explaining my dilemma(s) or perhaps my questions are uninteresting or/and unsolvable.
 
With a few adjustments I made the code work for an entire block (see below). It will adjust the attributes within the chosen block and set them to their original standard values.
 
However, it adjusts ALL the attributes in the chosen block. I only want to change the attribute that was selected with the cursor.
 
Any ideas out there?
  1. Option ExplicitPublic Sub SelectBlockAndUpdateTextStyle()Dim MyBlock As AcadBlockReferenceDim SelectedBlock As VariantDim i As VariantDim MyWidth As IntegerMyWidth = 1#ThisDrawing.Utility.GetEntity MyBlock, SelectedBlock, "Select object:"If MyBlock.ObjectName = "AcDbBlockReference" Then   If MyBlock.HasAttributes Then       Dim MyBlockAttribute As Variant       MyBlockAttribute = MyBlock.GetAttributes       For i = LBound(MyBlockAttribute) To UBound(MyBlockAttribute)           If Not MyBlockAttribute(i).StyleName = "STANDARD" Then           MyBlockAttribute(i).StyleName = "STANDARD"           MyBlockAttribute(i).ScaleFactor = MyWidth           End If           MyBlockAttribute(i).Update       Next   End IfElse   MsgBox "You didn't select an AutoCAD block. Better luck next time."End IfEnd Sub
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 22:44:08 | 显示全部楼层
I've posted the hint on your e-mail,
check it
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 22:46:50 | 显示全部楼层
 
Don't take it personal... It is more likely that you're not getting (much?) support, as you're coding in VBA, rather than in Visual LISP, or .NET, methinks.
 
I could be mistaken, as I am not adept at coding VBA, but perhaps using GetSubEntity Method in lieu of GetEntity Method would be advantageous, no?
回复

使用道具 举报

16

主题

43

帖子

33

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-6 22:51:50 | 显示全部楼层
Thanks Oleg I replied to your email
 
Thank you RenderMan. I like that possible solution. I looked into it and will need to work with it, but it may just work for my needs. Thanks!
I realize that I'm going to have to move on to one of the other programming languages. I've been holding out. I'm disappointed in AutoCAD for moving away from a language that has been used for many years and can be used in other applications (i.e. Excel). I know nothing of Visual LISP or .NET. Perhaps they work in other applications as well?
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 22:58:55 | 显示全部楼层
 
You're welcome; hope it helps.
 
 
Well, VBA has been 'dead or dying' through attrition for years, and is no longer supported by MS. Interestingly, however, is that in a recent developer survey the option of VBA7 was listed, though it did not have many votes. So you never know.
 
Visual LISP, while syntactically different than that of VBA, allows one access to both the LISP API, and the ActiveX API (i.e., VBA). I still have access to Document and Application level Objects, and can even interface with external Objects. Too many examples to post them all, but as a small sample set, these include Scripting.FileSystemObject, Shell.Application, WScript.Shell, and even Sapi.SpVoice Objects.
 
More on getting started with .NET development for AutoCAD.
 
HTH
回复

使用道具 举报

16

主题

43

帖子

33

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-6 23:05:57 | 显示全部楼层
Actually that helped a lot. I have some code now that works for what I need. I need to somehow add a "Do Until" user clicks "ENTER" twice or something to that effect so that the macro will continue running until the user is done, but your help definitely pointed me in the right direction. I appreciate it.
 
I didn't realize that MS no longer supports VBA either. Thats good to know. I appreciate the link. I guess I'm going to have to bite the bullet and begin Visual LISP or .NET as a newbie .
 
If you (or anyone willing to help) has some input as to how to make the routine below continue as long as the user wishes - please feel free to point me along the right path
 
Thank you again!
 
  1. Option ExplicitSub Example_GetSubEntity()   Dim Object As Object   Dim PickedPoint As Variant, TransMatrix As Variant, ContextData As Variant   Dim MyStyle As String   Dim MyWidth As Integer   Dim i As Variant   MyStyle = "STANDARD"   MyWidth = 1#   On Error GoTo NOT_ENTITYTRYAGAIN:   ThisDrawing.Utility.GetSubEntity Object, PickedPoint, TransMatrix, ContextData           If Not Object.StyleName = MyStyle Then           Object.StyleName = MyStyle           Object.ScaleFactor = MyWidth           End If           Object.Update   Exit SubNOT_ENTITY:   If MsgBox("You have not selected an object.  Click OK to try again.", _              vbOKCancel & vbInformation) = vbOK Then       Resume TRYAGAIN   End IfEnd Sub
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 23:08:46 | 显示全部楼层
You're welcome; happy to help.
 
Just a guess, but consider the 'Do...Loop', using the While keyword?   
 
... Oleg knows _far_ more than I about this.
回复

使用道具 举报

16

主题

43

帖子

33

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-6 23:13:19 | 显示全部楼层
I think I can make a Do loop work with one or the other - either the "Until" or the "While" keyword. However, I do not know the proper syntax to say "until the user hits ENTER" twice or something similar.
 
I'm not very familiar with your work here but I agree with your insight on Oleg. He has helped me more that I could ever repay (if I wasn't a poor broke drafter) over the years. He is an awesome source of help as well as a friend
 
Thank you again
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 23:22:38 | 显示全部楼层
what the biggest trout you caught for these years?
e-mail me, I've forgot about
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 11:34 , Processed in 0.450960 second(s), 72 queries .

© 2020-2025 乐筑天下

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