乐筑天下

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

[编程交流] Retrive length + insertion poi

[复制链接]

14

主题

29

帖子

15

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-6 14:54:25 | 显示全部楼层 |阅读模式
Hi,
 
I have a code that retrieves length of a line by selection and places this length as a text. The position for placement of text is done by .getpoint. Hence I have to click the line twice, once to retreive the length and another time to get the insertion point to place the text. Please help me with this such that in one click i should have length as well as insertion point of that place for placing text
 
Below is the code:
 
  1. Dim SOS As AcadSelectionSetDim objSS As AcadSelectionSetDim intCode(0) As IntegerDim varData(0) As VariantDim objEnt As AcadEntityDim entLine As AcadLineDim entPoly As AcadPolylineDim entLWPoly As AcadLWPolylineDim lenstring As Stringa = 1 For Each SOS In ThisDrawing.SelectionSets    If SOS.Name = "MySS" Then       ThisDrawing.SelectionSets("MySS").Delete    Exit For    End If Next intCode(0) = 0: varData(0) = "LINE,POLYLINE,LWPOLYLINE" ThisDrawing.SelectionSets.Add ("MySS") Set objSS = ThisDrawing.SelectionSets("MySS") objSS.SelectOnScreen intCode, varData If objSS.Count < 1 Then    MsgBox "No lines and polylines selected!" Exit Sub End IfDim endPoint As Variant For Each objEnt In objSS Select Case objEnt.ObjectName    Case "AcDbLine"       Set entLine = objEnt       endPoint = entLine.endPoint       lenstring = Round(entLine.Length)  '  MsgBox lenstring    Case "AcDb2dPolyline"       Set entPoly = objEnt       lenstring = Round(entPoly.Length)     ' MsgBox lenstring    Case "AcDbPolyline"       Set entLWPoly = objEnt     lenstring = Round(entLWPoly.Length)    ' MsgBox lenstring    End Select  Next'*******************************************************************************************'*******************************************************************************************'*******************************************************************************************Dim Point As VariantDim x As DoubleDim y As DoubleDim z As DoubleOn Error Resume Next'hide the UserFormfrmKP.Hide'ask user to select a pointPoint = ThisDrawing.Utility.GetPoint(, "Select a point")x = Point(0): y = Point(1): z = Point(2)'redisplay the UserFormfrmAPId.Show'MsgBox x'MsgBox y'**********************************************************************************************'*******************************************************************************************'*******************************************************************************************Dim textObj As AcadMTextDim textobj1 As AcadMText   Dim textString As String   Dim insertionPoint(0 To 2) As Double   Dim height As Double   Dim textstring1 As String   ' Define the text object   textString = Round(lenstring, 2) '& vbCr & Round(txty.Value)   insertionPoint(0) = x: insertionPoint(1) = y: insertionPoint(2) = 0    height = 22    'MsgBox textStringSet textObj = ThisDrawing.ModelSpace.AddText(textString & " m", insertionPoint, height)  
 
 
 
Thanks and Regards,
Priyanka
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 15:49:33 | 显示全部楼层
Instead of using a selection set you could use the ThisDrawing.Utility.GetEntity method.  That method will return the point used to make the entity selection.
 
It will only work for one entity at a time, however.
回复

使用道具 举报

1

主题

10

帖子

7

银币

初来乍到

Rank: 1

铜币
9
发表于 2022-7-6 16:12:19 | 显示全部楼层
Where, in relation to the line, do you want to place the text?
 
ska
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 22:03 , Processed in 0.681475 second(s), 58 queries .

© 2020-2025 乐筑天下

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