tiger1337 发表于 2022-7-6 23:28:56

以下代码假设为钟面。dwg块与当前图形位于同一文件夹中:
 

Option Explicit
Public Sub InsertClock()
   Dim objBRef As AcadBlockReference
   Dim varPoint As Variant
   Dim intMin As Integer
   Dim intHour As Integer
   Dim BProps As Variant
   Dim tmpProp As AcadDynamicBlockReferenceProperty
   Dim intI As Integer

   'ask user for where to place the clock, the prompt goes
   '   through the command window
   varPoint = ThisDrawing.Utility.GetPoint(, "click where you want the clock")

   'ask for time
   intHour = ThisDrawing.Utility.GetInteger(vbCrLf & "Hour: ")
   intMin = ThisDrawing.Utility.GetInteger(vbCrLf & "Minute: ")

   'insert block (the ones and zeros are for scale and rotation)
   Set objBRef = ThisDrawing.ModelSpace.InsertBlock(varPoint, "ClockFace.dwg", 1, 1, 1, 0)

   'get properties of the block
   BProps = objBRef.GetDynamicBlockProperties

   'go find minute and hour properties and change them
   'the minute rotation property is called 'Angle'
   'the hour rotation property is called 'Angle1'

   For intI = LBound(BProps) To UBound(BProps)

       'grab one property

       Set tmpProp = BProps(intI)

       'check for minute hand
       If tmpProp.PropertyName = "Angle" Then
         tmpProp.Value = Math.Atn(1) * 4 - (CDbl(intMin) / 60) * 2 * Math.Atn(1) * 4 - 2 * Math.Atn(1)
       End If

       'check for hour hand
       If tmpProp.PropertyName = "Angle1" Then
         tmpProp.Value = Math.Atn(1) * 4 - (CDbl(intHour) / 12) * 2 * Math.Atn(1) * 4 - 2 * Math.Atn(1)
       End If

   Next intI

   'update block
   objBRef.Update

End Sub

 
好的,现在我想修改一下这段代码,我只是不知道语法。我希望当用户选择一个点插入时钟时,时钟的虚线版本沿着光标跟随。你知道我的意思吗?它使它变得专业,当你需要查看时钟需要去哪里时,它变得更容易。
 
谢谢
~老虎1337

tiger1337 发表于 2022-7-6 23:33:25

如果我能把“Success”拼写对的话会有帮助

dbroada 发表于 2022-7-6 23:36:32

很不错的。我要花更长的时间才能到达那里!
这是一个我从未解决过的问题。有一场讨论正在进行中http://www.cadtutor.net/forum/showthread.php?50613-使用LISP&,在循环时重复插入块。虽然我还没有真正读过别人说的话。

tiger1337 发表于 2022-7-6 23:39:34

哈哈,谢谢戴夫!
 
这是我第一次使用动态块。你能给我简单介绍一下你是如何把这些角度参数添加到这两条线上的吗?我试图在我已经创建的另一个块上复制相同的东西。然而,我在实际应用角度参数时把事情搞砸了。
 
提前感谢,
老虎1337

dbroada 发表于 2022-7-6 23:43:19

我不经常使用旋转,所以这对我来说也很容易出错。在本例中,每只手需要一个参数和一个动作。我发现组合的很难使用,所以一次只使用一个参数|动作。我只是添加了以圆心为基点的参数,并选择了12点钟的位置(我想)作为其位置。然后我进入属性,使其具有0个夹点。调用旋转动作,选择旋转参数并选择垂直线,我想就是这样。以类似的方式重复时针。

tiger1337 发表于 2022-7-6 23:46:56

是的,成功了

tiger1337 发表于 2022-7-6 23:50:51

叹气我做错了什么事,我想不出来。
 
好的,这就是我要做的。我的画上有一系列的物体。我高亮显示所有这些,并使用WBLOCK将其保存为块dwg。现在,在这个方块上有两个箭头(你知道那些有箭头和圆圈的箭头)。我通过进入块编辑器并在这些半径不同的箭头的中心应用旋转参数来赋予这个块动态属性(相信我,我已经尝试了很多不同的组合)好的,问题是,一旦我运行程序(与我之前发布的脚本相同),大部分块看起来都很好。除此之外,一个或两个箭头出现在屏幕的某个地方。我说一个或两个,因为这取决于我首先创建块的方式。每次我从头开始都会发生不同的事情。我在拔头发。我肯定做错了什么事,但我想不出来。样本时钟绘图工作完美!
 
~老虎1337

dbroada 发表于 2022-7-6 23:52:45

张贴你的区块,有人会看到它

tiger1337 发表于 2022-7-6 23:56:30

这是块:
 
模块1.dwg

tiger1337 发表于 2022-7-6 23:57:40

似乎发生的事情是,不仅箭头围绕自身旋转,而且围绕图形中的其他点旋转。
页: 1 [2]
查看完整版本: 使用一个块生成多个