VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Invalid input

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
Demasure1
4970 Views, 12 Replies

Invalid input

Hello,

 

I have added a photo of the problem i get. When i run my vba program i get a error on this line:

 

 oDblkProp.Value = txtHoogte

 

I don't know what the problem is. 

the error is : Run-Time error ' -2145386493 ( 80200003)'

                    Invalid Input

 

How dan i fix this problem?

 

here is a copy of my vba-code:

 

Dim objBlok1 As AcadBlockReference
Dim strPath As String
Dim oprops As Variant
Dim oDblkProp As AcadDynamicBlockReferenceProperty
Dim i As Integer

dblInvoegpunt(0) = 0: dblInvoegpunt(1) = 0: dblInvoegpunt(2) = 0
Set objBlok1 = ThisDrawing.ModelSpace.InsertBlock(dblInvoegpunt, "C:\Autocad\Definitieve blocks\1.Onderkast\1.Vooraanzichten\Niet Beplakt\Vooraanzicht.NB.Doorlopende Stijlen.dwg", 1#, 1#, 1#, 0#)

If objBlok1.IsDynamicBlock Then
oprops = objBlok1.GetDynamicBlockProperties
For i = 0 To UBound(oprops)
Set oDblkProp = oprops(i)
If oDblkProp.PropertyName = "Hoogte" Then
'oDblkProp.Value = "txtHoogte" 'Hoogte van de kast
oDblkProp.Value = txtHoogte
Exit For
End If
Next
End If

 

Thankyou 

12 REPLIES 12
Message 2 of 13
RICVBA
in reply to: Demasure1

as you can read from AutoCAD ActiveX and VBA Reference, "PropertyName" property of "AcadDynamicBlockReferenceProperty" object is read-only: you can't set it, you can only read it

Message 3 of 13
Demasure1
in reply to: RICVBA

How can i change that? 

 

Message 4 of 13
Demasure1
in reply to: RICVBA

How to change the read only? i don't see the answer..
Message 5 of 13
RICVBA
in reply to: Demasure1

you can't through VBA simply

the online reference for "PropertyName" property of "AcadDynamicBlockReferenceProperty" object says "Property names are guaranteed to be unique among all properties on a given block reference"

which is the reason it's a read-only property: VBA won't let you set a name that could violate this uniqueness requirement

 

don't know whether lisp could help you, but I'd guess would not

Message 6 of 13
Demasure1
in reply to: RICVBA

And what i i make the name unique of every block? Like Height1, Height2,Height3, ... Would it work then?


if the propertyname is unique could it work then ?

 

a college of mine says its because there are more propertynames with the name height and because of that i get the error

Message 7 of 13
RICVBA
in reply to: Demasure1

as long as you deal with a read-only property you can't assign it any value

 

Message 8 of 13
Demasure1
in reply to: RICVBA

I found a solution 😄 

 

txtHoogte = frmKast.txtHoogte.Value

 

i added this code: 

Dim HoogteKast As Double
HoogteKast = txtHoogte

 

and replaced this code: 

oDblkProp.Value = HoogteKast

 

No errors anymore,

------------------------------------------------------------------------------------------------------------------------------------------------------- 

Sorry but i have a other question.

I put my codes in a module. But how can i run the min my form? 

I tryed:

 

If chkCoAlgemeen = True Then  ' when it need to be loaded
Call Mod_VAZAlgemeen '( modulename)
End If

 

But when i run my program nothing happens

in autocad i see: 

Command: Regenerating model.

 

Its the only thing that happens.

Do you know what i have to do? 

Message 9 of 13
RICVBA
in reply to: Demasure1

I must apologize since I only now realize I was telling you about "PropertyName" property of "AcadDynamicBlockReferenceProperty" object while you asked for its "Value" property.

And while the former is read-only, this latter is read-write. Glad to see you already solved your problem

 

as for your last question, see the specific topic you already opened.

 

Message 10 of 13
jomartinez2G9JM
in reply to: RICVBA

Sub ScanBlks123()
    Dim dybprop As Variant, i As Integer
    Dim bobj As AcadEntity
     Dim ThisDrawing As AcadDocument
         Set ThisDrawing = AcadApplication.ActiveDocument
  For Each bobj In ThisDrawing.ModelSpace 'Get AutoCAD Entity's
    Debug.Print bobj.ObjectName
        If bobj.ObjectName = "AcDbBlockReference" Then 'Check if BlockRef
            If bobj.IsDynamicBlock Then 'Check to see if it is a Dynamic Block
            dybprop = bobj.GetDynamicBlockProperties
                 If bobj.EffectiveName Like "FSM4L*" Then 'Finds Dynamic Block NAME
                 dybprop = bobj.GetDynamicBlockProperties
                For i = LBound(dybprop) To UBound(dybprop) 'Goes through Results
                    If dybprop(i).PropertyName = "Distance8" Then 'Looks for the PropertyName
                    dybprop(i).Value = "20" 'Change the Value of the PropertyName
                    End If
                Next i
                End If
            End If
        End If
        Next
End Sub

Public Sub ScanBlks() 'visib code
    Dim dybprop As Variant, i As Integer
    Dim bobj As AcadEntity
    Dim ThisDrawing As AcadDocument
    Dim abc As String
   With Workbooks("Make-A-Run Trial 02(phase two_01)")
 'abc = ThisWorkbook.Worksheets("Macro1").Range("s3").Value
    Set ThisDrawing = AcadApplication.ActiveDocument
    With Sheets("Configurations")
    abc = Range("O5")
    For Each bobj In ThisDrawing.ModelSpace
        If bobj.ObjectName = "AcDbBlockReference" Then
            If bobj.IsDynamicBlock Then
                If bobj.EffectiveName Like "FSM4L*" Then
                    dybprop = bobj.GetDynamicBlockProperties
                    For i = LBound(dybprop) To UBound(dybprop)
                        If dybprop(i).PropertyName = "Visibility1" Then
                            dybprop(i).Value = "TF"
                            ThisDrawing.Regen acActiveViewport
                        End If
                    Next i
                End If
            End If
        End If
    Next
    SendAutoCADCommands
    End With
End With
End Sub

Hello everyone, good morning, I am having a very similar issue to the one already answered but I'm having trouble resolving it by referencing this answer, hopefully someone can help me? I am trying to stretch a dynamic block but am having difficulty doing so. I have a fully functioning code to change visibility on a dynamic block, so I thought it'd be quite similar and easy to figure out but apparently not. I'll post both codes and a dwg. of my block if it helps. Thank you!

Message 11 of 13

the "Stretch" act usually is associated with a "point" or "linear", so the dynamic property's value should be corresponding to the parameter. for "point", the Stretch action results in 2 properties: "[property name]  X" and "[property name] Y", each expect a real number (Double, in VBA); while for "linear" parameter, the corresponding property expect a real number (Double) as input.

 

So, it is very simple to fix your code -  change "20" (string) to 20.0 (number), as long as the value is in allowed scope (the linear parameter may have min and/or max value specified, as you surely know):

 

                ... ...
For i = LBound(dybprop) To UBound(dybprop) 'Goes through Results If dybprop(i).PropertyName = "Distance8" Then 'Looks for the PropertyName // dybprop(i).Value = "20" 'Change the Value of the PropertyName
dybprop(i).Value = 20.0 End If Next i
... ...

 

Norman Yuan

Drive CAD With Code

EESignature

Message 12 of 13

Good morning Norman,

 

You are correct, I also found out that you can put a hashtag ahead of the number and this will work as well. The thing that I am struggling with now is setting a consecutive loop of inserting the blocks, adjusting the length by the "stretch" and adjusting the visibility. I have the code for inserting blocks in a loop, where the coordinates, scale factors and rotation angle can all be defined, but trying to throw the stretch and visibility options in there is giving me a hard time. I have the code to modify the stretch and visbility properties individually now (thanks to your last comment) but I can't seem to mix it all together. Maybe I can post it on here and you can take a look at it? It'd be greatly appreciated. Also if anyone else is working on a similar project, feel free to open up the content, it's meant to be super user-friendly.

 

Thank you!

Message 13 of 13

*UNABLE TO UPLOAD EXCEL WORKBOOK*

'Reference FOR WORKING CODE

'THIS CODE WILL INSERT STATIC BLOCKS WHILE MANIPULATING THE PLOTTING COORDINATES, X-Y-Z, SCALE, X-Y-Z-, AND ROTATION ANGLE
Sub Start_Up01()

'Declaring the necessary variables.
Dim acadApp As Object
Dim acadDoc As Object
Dim acadBlock As Object
Dim LastRow As Long
Dim I As Long
Dim InsertionPoint(0 To 2) As Double
Dim BlockName As String
Dim BlockScale As ScaleFactor
Dim RotationAngle As Double

'Activate the coordinates sheet and find the last row.
With Sheets("Coordinates")
.Activate
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With

'Check if there are coordinates for at least one circle.
If LastRow < 2 Then
MsgBox "There are no coordinates for the insertion point!", vbCritical, "Insertion Point Error"
Exit Sub
End If

'Check if AutoCAD application is open. If is not opened create a new instance and make it visible.
On Error Resume Next
Set acadApp = GetObject(, "AutoCAD.Application")
If acadApp Is Nothing Then
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True
End If

'Check (again) if there is an AutoCAD object.
If acadApp Is Nothing Then
MsgBox "Sorry, it was impossible to start AutoCAD!", vbCritical, "AutoCAD Error"
Exit Sub
End If
On Error GoTo 0

'If there is no active drawing create a new one.
On Error Resume Next
Set acadDoc = acadApp.ActiveDocument
If acadDoc Is Nothing Then
Set acadDoc = acadApp.Documents.Add
End If
On Error GoTo 0

'Check if the active space is paper space and change it to model space.
If acadDoc.ActiveSpace = 0 Then '0 = acPaperSpace in early binding
acadDoc.ActiveSpace = 1 '1 = acModelSpace in early binding
End If

On Error Resume Next
'Loop through all the rows and add the corresponding blocks in AutoCAD.
With Sheets("Coordinates")
For I = 2 To LastRow
'Set the block name.
BlockName = .Range("D" & I).Value
'If the block name is not empty, insert the block.
If BlockName <> vbNullString Then
'Set the insertion point.
InsertionPoint(0) = .Range("A" & I).Value
InsertionPoint(1) = .Range("B" & I).Value
InsertionPoint(2) = .Range("C" & I).Value
'Initialize the optional parameters.
BlockScale.X = 1
BlockScale.Y = 1
BlockScale.Z = 1
RotationAngle = 0
'Set the optional parameters (if there are values on the corresponding ranges).
If .Range("E" & I).Value <> vbNullString Then BlockScale.X = .Range("E" & I).Value
If .Range("F" & I).Value <> vbNullString Then BlockScale.Y = .Range("F" & I).Value
If .Range("G" & I).Value <> vbNullString Then BlockScale.Z = .Range("G" & I).Value
If .Range("H" & I).Value <> vbNullString Then RotationAngle = .Range("H" & I).Value
'Add the block using the sheet data (insertion point, block name, scale factors and rotation angle).
'The 0.0174532925 is to convert degrees into radians.
Set acadBlock = acadDoc.ModelSpace.InsertBlock(InsertionPoint, BlockName, _
BlockScale.X, BlockScale.Y, BlockScale.Z, RotationAngle * 0.0174532925)
End If
Next I
End With


acadApp.ZoomExtents

'Release the objects.
Set acadBlock = Nothing
Set acadDoc = Nothing
Set acadApp = Nothing


MsgBox "Your Pattern is Now in AutoCAD!", vbInformation, "Finished"

End Sub

 

 

'Current Code with Issue

Option Explicit

'A custom type that holds the scale factors of the block.
Private Type ScaleFactor
X As Double
Y As Double
Z As Double
End Type

Sub DynBlocksTest()

'--------------------------------------------------------------------------------------------------------------------------


'--------------------------------------------------------------------------------------------------------------------------

'Declaring the necessary variables.
Dim acadApp As Object
Dim acadDoc As Object
Dim acadBlock As Object
Dim LastRow As Long
Dim I As Long
Dim InsertionPoint(0 To 2) As Double
Dim BlockName As String
Dim BlockScale As ScaleFactor
Dim RotationAngle As Double
Dim dybprop As Object, O As Long
Set dybprop = acadBlock.GetDynamicBlockProperties
For O = LBound(dybprop) To UBound(dybprop)
'Activate the coordinates sheet and find the last row.
With Sheets("Coordinates")
.Activate
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With

'Check if there are coordinates for at least one circle.
If LastRow < 2 Then
MsgBox "There are no coordinates for the insertion point!", vbCritical, "Insertion Point Error"
Exit Sub
End If

'Check if AutoCAD application is open. If is not opened create a new instance and make it visible.
On Error Resume Next
Set acadApp = GetObject(, "AutoCAD.Application")
If acadApp Is Nothing Then
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True
End If

'Check (again) if there is an AutoCAD object.
If acadApp Is Nothing Then
MsgBox "Sorry, it was impossible to start AutoCAD!", vbCritical, "AutoCAD Error"
Exit Sub
End If
On Error GoTo 0

'If there is no active drawing create a new one.
On Error Resume Next
Set acadDoc = acadApp.ActiveDocument
If acadDoc Is Nothing Then
Set acadDoc = acadApp.Documents.Add
End If
On Error GoTo 0

'Check if the active space is paper space and change it to model space.
If acadDoc.ActiveSpace = 0 Then '0 = acPaperSpace in early binding
acadDoc.ActiveSpace = 1 '1 = acModelSpace in early binding
End If

On Error Resume Next
'Loop through all the rows and add the corresponding blocks in AutoCAD.
With Sheets("Coordinates")
For I = 2 To LastRow
'Set the block name.
BlockName = .Range("D" & I).Value
If acadBlock.IsDynamicBlock Then
'If the block name is not empty, insert the block.
If BlockName <> vbNullString Then
'Set the insertion point.
InsertionPoint(0) = .Range("A" & I).Value
InsertionPoint(1) = .Range("B" & I).Value
InsertionPoint(2) = .Range("C" & I).Value
'Initialize the optional parameters.
BlockScale.X = 1
BlockScale.Y = 1
BlockScale.Z = 1
RotationAngle = 0
'Set the optional parameters (if there are values on the corresponding ranges).
If .Range("E" & I).Value <> vbNullString Then BlockScale.X = .Range("E" & I).Value
If .Range("F" & I).Value <> vbNullString Then BlockScale.Y = .Range("F" & I).Value
If .Range("G" & I).Value <> vbNullString Then BlockScale.Z = .Range("G" & I).Value
If .Range("H" & I).Value <> vbNullString Then RotationAngle = .Range("H" & I).Value
If .Range("I" & I).Value <> vbNullString Then dybprop(O).Value = .Range("I" & I).Value
dybprop = acadBlock.GetDynamicBlockProperties
'For O = LBound(dybprop) To UBound(dybprop)
'If dybprop(O).PropertyName = "Distance8" Then dybprop(O).Value = .Range("I" & i).Value
'Add the block using the sheet data (insertion point, block name, scale factors and rotation angle).
'The 0.0174532925 is to convert degrees into radians.
Set acadBlock = acadDoc.ModelSpace.InsertBlock(InsertionPoint, BlockName, _
BlockScale.X, BlockScale.Y, BlockScale.Z, RotationAngle * 0.0174532925)
End If
End If

Next I
End With
Next O

'Zoom in to the drawing area.
acadApp.ZoomExtents

'Release the objects.
Set acadBlock = Nothing
Set acadDoc = Nothing
Set acadApp = Nothing

'Inform the user about the process.
MsgBox "The blocks were successfully inserted in AutoCAD!", vbInformation, "Finished"

End Sub

Sub ClearAll()

Dim LastRow As Long

'Find the last row and clear all the input data..
With Sheets("Coordinates")
.Activate
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("A2:H" & LastRow).ClearContents
.Range("A2").Select
End With

End Sub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost