乐筑天下

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

[编程交流] 绘制垂直线

[复制链接]

14

主题

42

帖子

28

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-6 22:43:48 | 显示全部楼层 |阅读模式
大家好,
 
我是新手,如果你觉得这很烦人,请原谅我的愚蠢。
 
这就是问题所在。我目前正在为佛兰德政府制作地图。在你看来,有些事情会一次又一次地返回,所以我想让整个过程加快一点。
 
我必须在现有的线上画两条垂直的线,就像这样:
 
_____-->l _____l
 
当我从左向右单击点时:
______
|         |
反过来说。
 
线路长度恒定,为0.3m
 
到目前为止,我有以下内容,但由于不同的数组类型,它不起作用,我想使用“GetPoint”过程。
 
 
  1. Dim p0 as AcadPoint
  2. Dim p1 as AcadPoint
  3. Dim p2(1) as double
  4. Dim p3(1) as Double
  5. 'The following only seems to work when I Dim p0 and p1 as variant
  6. Set p0 = ThisDrawing.Utility.GetPoint()
  7. Set p1 = ThisDrawing.Utility.GetPoint()
  8. 'Calculate the first point
  9. p2(0) = p0(0) - 0.3 * (p0(1) - p1(1))/((p0(0)-p1(0))^2+(p0(1)-p1(1))^2)^0.5
  10. 'And so on for the other coördinates
  11. 'Then draw the lines
  12. Dim pLine1 as AcadPolyLine
  13. Set pLine1 = Thisdrawing.Application.ActiveDocument.Modelspade.Addline(p0, p2)
  14. 'Dito for the second line

 
 
编程,已经有一段时间了,所以如果你连这件简单的事情都做不到,那真是令人沮丧。
 
谢谢你的帮助!
阿诺特
回复

使用道具 举报

9

主题

59

帖子

38

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
58
发表于 2022-7-6 22:57:03 | 显示全部楼层
我想你是想得到这样的东西:
 
 
  1. Sub TestDrawLines()
  2.    Dim p0 As Variant
  3.    Dim p1 As Variant
  4.    Dim p2(2) As Double
  5.    Dim p3(2) As Double
  6.    On Error GoTo ErrorTrapping
  7.    'The following only seems to work when I Dim p0 and p1 as variant
  8.    p0 = ThisDrawing.Utility.GetPoint()
  9.    p1 = ThisDrawing.Utility.GetPoint(p0)
  10.    'Calculate the first point
  11.    p2(0) = p0(0) - 0.3 * (p0(1) - p1(1)) / ((p0(0) - p1(0)) ^ 2 + (p0(1) - p1(1)) ^ 2) ^ 0.5
  12.    'And so on for the other coordinates
  13.    'Then draw the lines
  14.    Dim Line1 As AcadLine
  15.    Set Line1 = ThisDrawing.ModelSpace.AddLine(p0, p2)
  16.    'Dito for the second line
  17.    Exit Sub
  18. ErrorTrapping:
  19.    MsgBox "Program ends due to error!"
  20. End Sub
回复

使用道具 举报

14

主题

42

帖子

28

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-6 22:59:32 | 显示全部楼层
嗨Joro
 
似乎就是这样!谢谢希望我的计算正确
 
谢谢
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 23:09:18 | 显示全部楼层
对于多输入,也可以尝试此代码
  1. Option Explicit
  2. '' ---> request check "Break on Unhandled Errors" in  Tools-> Options -> General tab  <---
  3. Public Sub DrawTicks()
  4. Dim stPt As Variant, endPt As Variant
  5. Dim intOsm As Integer
  6. intOsm = ThisDrawing.GetVariable("OSMODE")
  7. ThisDrawing.SetVariable "OSMODE", 0
  8. Dim Pi As Double
  9. Pi = Atn(1#) * 4
  10. Do
  11. On Error Resume Next
  12. stPt = ThisDrawing.Utility.GetPoint(, vbCrLf & "First point (ENTER or Right click to exit): ")
  13. If Err Then
  14. Err.Clear
  15. Exit Do
  16. End If
  17. On Error GoTo 0
  18. endPt = ThisDrawing.Utility.GetPoint(stPt, vbCrLf & "End point: ")
  19. If Err Then
  20. Err.Clear
  21. Exit Do
  22. End If
  23. On Error GoTo 0
  24. Dim ang As Double
  25. ang = ThisDrawing.Utility.AngleFromXAxis(stPt, endPt)
  26. Dim tmp As Variant
  27. tmp = ThisDrawing.Utility.PolarPoint(stPt, ang + Pi / 2, 0.3)
  28. Dim oLine As AcadLine
  29. Set oLine = ThisDrawing.ModelSpace.AddLine(stPt, endPt)
  30. Set oLine = ThisDrawing.ModelSpace.AddLine(stPt, tmp)
  31. tmp = ThisDrawing.Utility.PolarPoint(endPt, ang + Pi / 2, 0.3)
  32. Set oLine = ThisDrawing.ModelSpace.AddLine(endPt, tmp)
  33. Loop
  34. On Error GoTo 0
  35. ThisDrawing.SetVariable "OSMODE", intOsm
  36. End Sub

 
谢谢你的帮助!
回复

使用道具 举报

14

主题

42

帖子

28

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-6 23:13:03 | 显示全部楼层
开始新事物的时间:
http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20指南/索引。html?url=WS1a9193826455f5ff2566ffd511ff6f8c7ca-4875。htm,主题编号=d0e51
在我看来
干杯
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 23:17:48 | 显示全部楼层
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 23:23:57 | 显示全部楼层
Just a dumb question why not use a line type ? All linetypes are created with known dimensions and when used at correct scale reflect the true dimension.   
 
This a 9m spacing with 3m gap
*LANE1000,____        _____        ____
A,3.00,-9.00
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 23:34:18 | 显示全部楼层
Here is two procedures you sked for
try again

[code] Option Explicit'' request check "Break on Unhandled Errors" in General options' 1. draw lines by picking pointsPublic Sub DrawTicks()Dim stPt As Variant, endPt As VariantDim intOsm As IntegerintOsm = ThisDrawing.GetVariable("OSMODE")ThisDrawing.SetVariable "OSMODE", 0Dim PI As DoublePI = Atn(1#) * 4'create layer if this does not existsIf Not LayerExists("N_WLI2") Then AddLayer ("N_WLI2")DoOn Error Resume NextstPt = ThisDrawing.Utility.GetPoint(, vbCrLf & "First point (ENTER or Right click to exit): ")If Err ThenErr.ClearExit DoEnd IfOn Error GoTo 0endPt = ThisDrawing.Utility.GetPoint(stPt, vbCrLf & "End point: ")If Err ThenErr.ClearExit DoEnd IfOn Error GoTo 0Dim ang As Doubleang = ThisDrawing.Utility.AngleFromXAxis(stPt, endPt)Dim tmp As Varianttmp = ThisDrawing.Utility.PolarPoint(stPt, ang + PI / 2, 0.3)Dim oLine As AcadLineSet oLine = ThisDrawing.ModelSpace.AddLine(stPt, endPt)Set oLine = ThisDrawing.ModelSpace.AddLine(stPt, tmp)tmp = ThisDrawing.Utility.PolarPoint(endPt, ang + PI / 2, 0.3)Set oLine = ThisDrawing.ModelSpace.AddLine(endPt, tmp)LoopOn Error GoTo 0ThisDrawing.SetVariable "OSMODE", intOsmEnd Sub'2.0 for existing linesPublic Sub AddTicks()Dim sset As AcadSelectionSetDim dxfCode, dxfValueDim ftype(1) As IntegerDim fdata(1) As Variantftype(0) = 0: fdata(0) = "LINE"ftype(1) = 8: fdata(1) = "N_WLI2" '
回复

使用道具 举报

14

主题

42

帖子

28

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-6 23:38:55 | 显示全部楼层
Hi guys,
 
Right, i've had a bit of sleep and got on it straight away. The following is the end-product, and works just fine!
 
  1. Sub Kop3()   Dim p0 As Variant   Dim p1 As Variant   Dim p2(2) As Double   Dim p3(2) As Double   Dim pLine1, pLine2 As AcadLine      On Error GoTo ErrorTrapping          p0 = ThisDrawing.Utility.GetPoint(, "Eerste punt (ENTER of Rechtse klik om te verlaten):")   p1 = ThisDrawing.Utility.GetPoint(p0, "Eindpunt (ENTER of Rechtse klik om te verlaten):")      p2(0) = p0(0) - (0.3 * (p0(1) - p1(1)) / ((p0(0) - p1(0)) ^ 2 + (p0(1) - p1(1)) ^ 2) ^ 0.5)   p2(1) = p0(1) + (0.3 * (p0(0) - p1(0)) / ((p0(0) - p1(0)) ^ 2 + (p0(1) - p1(1)) ^ 2) ^ 0.5)      p3(0) = p1(0) - (0.3 * (p0(1) - p1(1)) / ((p0(0) - p1(0)) ^ 2 + (p0(1) - p1(1)) ^ 2) ^ 0.5)   p3(1) = p1(1) + (0.3 * (p0(0) - p1(0)) / ((p0(0) - p1(0)) ^ 2 + (p0(1) - p1(1)) ^ 2) ^ 0.5)   Set pLine1 = ThisDrawing.Application.ActiveDocument.ModelSpace.AddLine(p0, p2)   Set pLine2 = ThisDrawing.Application.ActiveDocument.ModelSpace.AddLine(p1, p3)      Dim Layer As AcadLayer   Set Layer = ThisDrawing.Application.ActiveDocument.Layers.Add("N_WLI2")   pLine1.Layer = "N_WLI2"   pLine2.Layer = "N_WLI2"      Exit Sub   ErrorTrapping:   MsgBox "Fout bij het aanduiden!"End Sub
 
Thanks for the help!
回复

使用道具 举报

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 23:45:30 | 显示全部楼层
Time to start new stuffs:
http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html?url=WS1a9193826455f5ff2566ffd511ff6f8c7ca-4875.htm,topicNumber=d0e51
In my opinion
Cheers
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

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

© 2020-2025 乐筑天下

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