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

Autocad VBA Userform to edit Parameters Manager dimensions

16 REPLIES 16
Reply
Message 1 of 17
mnash60
6783 Views, 16 Replies

Autocad VBA Userform to edit Parameters Manager dimensions

I have come to a road block, I am for a lost of how to connect the information that i type into textboxs and to change the values of dimensional constraint parameters ex. d1 d2 d3

 

Can you please help mePicture1.jpg 

16 REPLIES 16
Message 2 of 17
norman.yuan
in reply to: mnash60

AutoCAD 2010 introduced the Parameter/Constraint stuff, but no API was exposed. AutoCAD2011, however,  exposed the API in ObjectARX and ObjectARX .NET API. It is unfortunately there is no COM API exposed that you can use in VBA programming.

 

If you need to do programming on the Parameter/Constraint thing, you need to use Acad2011 and do either VC++ or .NET. No VBA (it dies anyway after Acad2011).

 

Message 3 of 17
mnash60
in reply to: norman.yuan

Is there any vba code out there that can at least get me to a finished product im trying to automaticly draw my detailed drawing with a userform or excel?

Message 4 of 17
mnash60
in reply to: mnash60

Can i modify this code to do it.

 

Sub PromptForDims()
Dim DimName As String, DimValue As Double

DimName = InputBox("Enter Parametric Dim name:")
DimValue = InputBox("Enter Parametric Dim value:")
Call EditParametricDim(DimName, DimValue)

End Sub

 

Private Sub EditParametricDim(ByVal ParamName As String, ByVal ParaValue As Double)
On Error Resume Next
Dim oDoc As AcadDocument, oEnity As Object, oRotDim As Object

Set oDoc = ThisDrawing
For Each oEnity In oDoc.ModelSpace
Set oRotDim = oEnity
If CStr(oRotDim.DimConstrName) = ParamName Then
    If Err.Number = 0 Then oRotDim.DimConstrExpression = ParaValue: Exit For
End If
     
    If Err.Number = 438 Then
    'Object doesn't have DimConstr objects
    Err.Clear
    Else
    'Some other error
    If Err.Number > 0 Then GoTo ErrHandler
    End If

Next
Exit Sub
ErrHandler: MsgBox Err.Description
End Sub

Message 5 of 17
solairamprasad
in reply to: mnash60

is there any possibility to edit the user variables in parametric manager by Autocad VBA.If yes please help me in this issue.

 

 

Message 6 of 17
cwilkes
in reply to: solairamprasad

did you ever find your answer for this? I'd love to have the code as well.
Message 7 of 17
sanganaksakha
in reply to: cwilkes

I don't think it is difficult.

 

I have done it using VisualLisp.

 

Message 8 of 17
jlok9
in reply to: sanganaksakha

Can you please post your VisualLisp routine?

I would like to know which variables to look for and hopefully adapt it to vba.

 

Thanks a bunch!

Message 9 of 17
cwilkes
in reply to: jlok9

I'll show you a quick sample of what I found. I still don't know if this works for "User Parameters," but it definitely works for dimensional constraints.:

 

Dim objfind As AcadObject
Dim dimrotfind As AcadDimRotated
Dim enclosuretopblock As AcadBlock

Set enclosuretopblock = acaddoc(1).Database.Blocks("ENCLOSURE")

For Each objfind In enclosuretopblock If TypeOf objfind Is AcadDimRotated Then Set dimrotfind = objfind If dimrotfind.DimConstrName = "D_ENC_LEN" Then dimrotfind.DimConstrExpression = enclen ElseIf dimrotfind.DimConstrName = "D_ENC_WID" Then dimrotfind.DimConstrExpression = encwid ElseIf dimrotfind.DimConstrName = "D_WT" Then dimrotfind.DimConstrExpression = wallthk End If End If Next

enclen, encwid, wallthk are doubles.

Message 10 of 17
Demasure1
in reply to: jlok9

Hello,

 

Did you find a code for inserting variables / parameters of a dynamic block into VBA?

 

Greetings

Message 11 of 17
cwilkes
in reply to: Demasure1

if you could tell me exactly what you're trying to do, I could try to fill you in. I still don't know about reading/writing what autocad calls "User Parameters," but as far as dimensional contraints, custom properties, and all that go, I could probably answer your question.

Message 12 of 17
Demasure1
in reply to: cwilkes

Well i have made a dynamic block

 

I got the Length, width added with a linear parameter

 

With my vba.program i should be able to modify these parameters.

I have a code written, but i get a error : " invalid input" 

 

i get the error on this line : " oDblkProp.Value = txtHoogte"

On a other forum they told me i had to change it into "oDblkProp.Value = txtHoogte.Text"

But is still does not work

 

this is my code:

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

Public txtHoogte as double

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

 

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

 

Do you know what i have to do to fix this error?

I need to do the same thing with other parameters

 

thanks

 

Message 13 of 17
cwilkes
in reply to: Demasure1

 
Message 14 of 17
cwilkes
in reply to: Demasure1

Sorry about that last empty post. Hit post on accident.

 

If you copy/pasted directly from your vba window, your issue is the quotes around "txtHoogte." You don't want those there. The way you have it now indicates that you'd like to set that property (that can only be numeric, not letters) to be the word "txtHoogte" when in reality, you want it to be the value of the variable txtHoogte. Just take out the quotes on this line and you should be fine: 'oDblkProp.Value = "txtHoogte" 'Hoogte van de kast

 

The final format should be oDblkProp.Value = txtHoogte 'Hoogte van de kast

 

haha is that Swedish?

Message 15 of 17
cwilkes
in reply to: Demasure1

sorry, I'm mistaken. didn't see the next line there. But I'm not seeing where you give txtHoogte a value. if txtHoogte is a text box, take out the Dim line for txtHoogte (you don't have to declare existing text boxes) and for VBA, you'll have to use txtHoogte.Caption I believe.

 

However, if you're trying to use txtHoogte as a variable, you'll have to assign it a value before you use it. Something like txtHoogte = tboxHoogte.Caption.

 

So if that's a text box, here's your new 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.Caption

Exit For
End If
Next
End If

 

__________________________________________________________________________
__________________________________________________________________________

 

and if txtHoogte is supposed to be a variable, this is your new code (note: you will have to have a text box called "TBoxHoogte" on your form):

Public txtHoogte as double

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

 

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

 

txtHoogte = TBoxHoogte.Caption

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

Exit For
End If
Next
End If

___________________________________________________________________

I'm not sure if you're new to this or not, but make sure you run code to regenerate your drawing at the end or you may not see any changes.

 

Good luck.

 

(by the way, I think Autodesk's website may have corrected something it thought was HTML in there, I just can't tell what it changed.)

Message 16 of 17
Demasure1
in reply to: cwilkes

Well i tryed what you send me but the error keeps coming back. i don't know what it is .. i checked everything a 100 times...

I also tryed this :" txtHoogte = CDbl(Val(frmKast.txtHoogte.Value))"

 

Its very strange if i run the program and i enter in my form 1500 the txtHoogte is 1500 but. Ill add a printscreen of what i mean.

 

txtHoogte = CDbl(Val(frmKast.txtHoogte.Value))

 

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

 

Exit For
End If
Next
End If

 

I still hope somebody can help me. 

Message 17 of 17
RICVBA
in reply to: Demasure1

see >answer<

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

Post to forums  

Autodesk Design & Make Report

”Boost