乐筑天下

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

[编程交流] 在命令行中粘贴文本

[复制链接]

18

主题

52

帖子

40

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-15 07:51:36 | 显示全部楼层 |阅读模式
你好
我从a复制文本。txt文件。
在AutoCad中,我用鼠标右键单击命令行,然后
单击insert(Einfügen),将在图形中创建所有矩形。
 
是否有方法仅在excel中复制文本,并将其带到AutoCad中
SendCommand命令?
 
谢谢你的帮助。
https://ibb.co/zXn36Y8
回复

使用道具 举报

15

主题

1052

帖子

58

银币

中流砥柱

Rank: 25

铜币
683
发表于 2022-7-15 08:06:55 | 显示全部楼层
这将首先检查AutoCAD是否打开,更改为模型空间,并将选定的每个单元格的文本发送到命令行。
 
  1. Sub CMDSend()
  2. ' Keyboard Shortcut: Ctrl+Shift+P
  3.     Dim app As Object, Doc As Object, Cmd As String, rng As Range, i As Long
  4.     On Error Resume Next
  5.     Set App = GetObject(, "AutoCAD.Application")
  6.     If app Is Nothing Then
  7.         MsgBox "AutoCAD isns't Open!", vbCritical, "Input Error"
  8.         Exit Sub
  9.     End If
  10.     Set Doc = app.ActiveDocument
  11.     'Check if the active space is paper space and change it to model space.
  12.     If Doc.ActiveSpace = 0 Then '0 = acPaperSpace in early binding
  13.        Doc.ActiveSpace = 1      '1 = acModelSpace in early binding
  14.     End If
  15.     Set rng = Selection  'set a range of cells
  16.     For Each rng In Selection.Cells
  17.       If rng.Value > 0 Then  'if cell isn't blank send command
  18.          Cmd = rng.Value
  19.          Doc.SendCommand Cmd & vbCr
  20.       End If
  21.     Next rng
  22. End Sub
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-15 08:21:48 | 显示全部楼层
您可以编写一个用于excel的矩形sub,只需传递4个角值x1 y1 x2 y2等。查看“pline”的结尾。我不是使用这种方法的专家,只是为了看看我能做些什么。
 
  1.   
  2. Public Sub Opendwg()
  3.     Dim acadApp As Object
  4.     Dim acadDoc As Object
  5. 'Check if AutoCAD application is open. If is not opened create a new instance and make it visible.
  6.     On Error Resume Next
  7.     Set acadApp = GetObject(, "AutoCAD.Application")
  8.     If acadApp Is Nothing Then
  9.         Set acadApp = CreateObject("AutoCAD.Application")
  10.         acadApp.Visible = True
  11.     End If
  12.     'Check (again) if there is an AutoCAD object.
  13.     If acadApp Is Nothing Then
  14.         MsgBox "Sorry, it was impossible to start AutoCAD!", vbCritical, "AutoCAD Error"
  15.         Exit Sub
  16.     End If
  17.     On Error GoTo 0
  18.     'If there is no active drawing create a new one.
  19.     On Error Resume Next
  20.     Set acadDoc = acadApp.ActiveDocument
  21.     If acadDoc Is Nothing Then
  22.         Set acadDoc = acadApp.Documents.Add
  23.     End If
  24.     On Error GoTo 0
  25.   
  26.     'Check if the active space is paper space and change it to model space.
  27.     If acadDoc.ActiveSpace = 0 Then '0 = acPaperSpace in early binding
  28.         acadDoc.ActiveSpace = 1     '1 = acModelSpace in early binding
  29.     End If
  30. End Sub
  31. Public Sub addline(x1, y1, z1, x2, y2, z2)
  32.   
  33. ' Create the line in model space
  34.     'Dim acadApp As Object
  35.     'Dim acadDoc As Object
  36.     Set acadApp = GetObject(, "AutoCAD.Application")
  37.     Set acadDoc = acadApp.ActiveDocument
  38.     Dim startpoint(0 To 2) As Double
  39.     Dim endpoint(0 To 2) As Double
  40.     Dim lineobj As Object
  41.     startpoint(0) = x1: startpoint(1) = y1: startpoint(2) = z1
  42.     endpoint(0) = x2: endpoint(1) = y2: endpoint(2) = z2
  43.     Set lineobj = acadDoc.ModelSpace.addline(startpoint, endpoint)
  44.     acadApp.ZoomExtents
  45.    
  46.     End Sub
  47.     Public Sub addcirc(x1, y1, z1, rad)
  48.   
  49. ' Create the circle in model space
  50.    ' Dim acadApp As Object
  51.    ' Dim acadDoc As Object
  52.     Set acadApp = GetObject(, "AutoCAD.Application")
  53.     Set acadDoc = acadApp.ActiveDocument
  54.     Dim cenpoint(0 To 2) As Double
  55.    
  56.     Dim circobj As Object
  57.    cenpoint(0) = x1: cenpoint(1) = y1: cenpoint(2) = z1
  58.     Set circobj = acadDoc.ModelSpace.addcircle(cenpoint, rad)
  59.     acadApp.ZoomExtents
  60.    
  61.     End Sub
  62.    
  63.    
  64.     Sub addpoly(cords, col)
  65.    
  66.     ' Dim acadApp As Object
  67.     ' Dim acadDoc As Object
  68.     Set acadApp = GetObject(, "AutoCAD.Application")
  69.     Set acadDoc = acadApp.ActiveDocument
  70.     Dim oPline As Object
  71.    
  72. ' add pline to Modelspace
  73. Set oPline = acadDoc.ModelSpace.AddLightWeightPolyline(cords)
  74. oPline.Color = col
  75. End Sub
  76.    
  77.     Sub alan1()
  78.    
  79.    
  80. ' This example adds a line in model space
  81. ' Define the start and end points for the line
  82.    
  83.     px1 = 1
  84.     px2 = 5
  85.     py1 = 1
  86.     py2 = 5
  87.     pz1 = 0
  88.     pz2 = 0
  89.    
  90. Call addline(px1, py1, pz1, px2, py2, pz2)
  91. End Sub
  92. Sub alan2()
  93.     px1 = 1
  94.     py1 = 1
  95.     pz1 = 0
  96.     Radius = 8.5
  97. Call addcirc(px1, py1, pz1, Radius)
  98. End Sub
  99. Sub alan3()
  100. 'Dim coords(0 To n) As Double
  101. Dim coords(0 To 5) As Double
  102. coords(0) = -6: coords(1) = 1:
  103. coords(2) = 3: coords(3) = 5:
  104. coords(4) = 7.55: coords(5) = 6.25:
  105. col = 1
  106.    
  107. Call addpoly(coords, col)
  108. End Sub
回复

使用道具 举报

18

主题

52

帖子

40

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-15 08:39:05 | 显示全部楼层
嗨,mhupp,嗨,bigal,
 
谢谢你的回答,慢慢来。
 
@我现在正在和医生一起做。send命令,将它们逐个单元格带到AutoCad。
在复制和粘贴到命令行的步骤中,在我看来,它比逐个单元格读取要快。
(手工制作)
我以为命令行中有一个insert命令可以从剪贴板粘贴
 
@比加尔
谢谢你的计划,有很多对我有用的方法。
 
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-15 08:55:26 | 显示全部楼层
选择范围Ctrl+C,单击Autocad命令行Ctrl+V不知道有多简单,啊,但我现在记得,如果某个任务不起作用,则会出现问题。选择列excel,单击编辑、特殊粘贴、脚本文本。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-5-25 01:03 , Processed in 1.422748 second(s), 73 queries .

© 2020-2025 乐筑天下

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