VB script issues

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I am a regular CAD user, but haven't really used scripting before in the product. I have a piece of code which apparently was created years ago by someone and should work, but doesn't. I am trying to debug and fix it if possible.
The code is supposed to prompt the user for a block name and then insert it, whilst allowing the user to specify insertion point, and the angle etc.
Would be very grateful if anyone could give the code a quick look through and see if there are any obvious issues.
EDIT - forgot to say, the prompt appears and I can enter a block name, it then allows me to click an insert point and a second point, but then nothing happens.
Many thanks
Matt
------------------------------------------
Option Explicit
Dim FirstPnt As Variant: Dim SecondPnt As Variant
Dim Angle As Double
Dim Name As String
Dim Xscale As Double: Dim Yscale As Double: Dim Yratio As Double
Dim DX As Double: Dim DY As Double
Dim Ratio As Boolean
Dim Blockobject As AcadEntity
Public Pick As Boolean
Public Sub Fblock()
On Error GoTo Errorhandler
Dim Errortxt As String
Dim Keyword As String
Do
'Show form and get values
Pick = False
frmFBlock.Show
If Not Pick Then Exit Sub
Name = frmFBlock.txtName
Yratio = Val(frmFBlock.txtYscale)
Ratio = frmFBlock.chkRatio
'Check blockname exists
If Checkblock() = False Then
MsgBox ("Block does not exist")
Exit Sub
End If
Do
'Pick first point, exit or return to settings
ThisDrawing.Utility.InitializeUserInput 1, "Settings eXit"
On Error Resume Next
FirstPnt = ThisDrawing.Utility.GetPoint(, "Pick head, or [Settings eXit] <Settings: ")
Errortxt = Err.Description
On Error GoTo Errorhandler
If Errortxt = "User input is a keyword" Then
Keyword = ThisDrawing.Utility.GetInput()
If Keyword = "eXit" Then Exit Sub
If Keyword = "Settings" Then Exit Do
End If
'Pick second point
ThisDrawing.Utility.InitializeUserInput 1
SecondPnt = ThisDrawing.Utility.GetPoint(FirstPnt, "Pick tail:")
'Calculate Xscale factor
DX = FirstPnt(0) - SecondPnt(0)
DY = FirstPnt(1) - SecondPnt(1)
Xscale = Sqr(DX ^ 2 + DY ^ 2)
'Calculate angle of block
Angle = ThisDrawing.Utility.AngleFromXAxis(FirstPnt, SecondPnt)
'Calculate Y ratio relative to X scale factor
If Ratio Then
Yscale = Xscale
Else
Yscale = Yratio * Xscale
End If
'Insert block
Set Blockobject = ThisDrawing.ModelSpace.InsertBlock(FirstPnt, Name, Xscale, Yscale, 1, Angle)
Loop While True
Loop While True
Exit Sub
Errorhandler:
MsgBox "Utility aborted", , "FlexiBlock"
End Sub
Function Checkblock()
Dim Check As AcadBlock
On Error Resume Next
Set Check = ThisDrawing.Blocks.Item(Name)
If Err <> 0 Then
Checkblock = False
Else
Checkblock = True
End If
End Function