hairyuga Posted February 27, 2009 Posted February 27, 2009 I'm getting an error "Argument not Optional" for InsertBlock when I try to insert a block from within the drawing. I don't get it! 'Create Panel Private Sub cmdCreatePanel_Click() Dim varPick As Variant Dim dblLength As Double Dim dblWidth As Double Dim dblHeight As Double Dim dblCenter(2) As Double Dim objEnt As Acad3DSolid Dim InsertionPoint As Variant Dim gpartref As McadPartReference Dim ProfileRef As AcadBlockReference Me.Hide 'get the input from user With ThisDrawing.Utility .InitializeUserInput 1 varPick = .GetPoint(, vbCr & "Pick a corner point: ") .InitializeUserInput 1 + 2 + 4, "" dblLength = .DistanceToReal(cmbPanelLength.Text, acEngineering) .InitializeUserInput 1 + 2 + 4, "" dblWidth = .DistanceToReal(cmbPanelWidth.Text, acEngineering) .InitializeUserInput 1 + 2 + 4, "" dblHeight = .DistanceToReal(cmbPanelHeight.Text, acEngineering) ' Return the current value of the insertion point InsertionPoint = varPick End With 'calculate center point from input dblCenter(0) = CDbl(varPick(0)) + (dblLength / 2) dblCenter(1) = CDbl(varPick(1)) + (dblWidth / 2) dblCenter(2) = CDbl(varPick(2)) + (dblHeight / 2) 'draw the entity Set objEnt = ThisDrawing.ModelSpace.AddBox(dblCenter, dblLength, _ dblWidth, dblHeight) 'get part reference Set gpartref = ThisDrawing.ModelSpace.AddCustomObject("AcmPartRef") gpartref.Origin = varPick 'insert Profile Block InsertionPoint = varPick Set ProfileRef = ThisDrawing.ModelSpace.InsertBlock(InsertionPoint, "P+P", varPick(0), varPick(1), varPick(2)) 'update entity objEnt.History = True objEnt.Update ThisDrawing.Regen acActiveViewport Me.Show End Su Quote
Lee Mac Posted February 27, 2009 Posted February 27, 2009 You will need to include a rotation argument in your insertblock expression - this argument is "not optional" Quote
Lee Mac Posted February 27, 2009 Posted February 27, 2009 I know almost nothing about VBA, but try this: 'Create Panel Private Sub cmdCreatePanel_Click() Dim varPick As Variant Dim dblLength As Double Dim dblWidth As Double Dim dblHeight As Double Dim dblCenter(2) As Double Dim objEnt As Acad3DSolid Dim InsertionPoint As Variant Dim gpartref As McadPartReference Dim ProfileRef As AcadBlockReference Me.Hide 'get the input from user With ThisDrawing.Utility .InitializeUserInput 1 varPick = .GetPoint(, vbCr & "Pick a corner point: ") .InitializeUserInput 1 + 2 + 4, "" dblLength = .DistanceToReal(cmbPanelLength.Text, acEngineering) .InitializeUserInput 1 + 2 + 4, "" dblWidth = .DistanceToReal(cmbPanelWidth.Text, acEngineering) .InitializeUserInput 1 + 2 + 4, "" dblHeight = .DistanceToReal(cmbPanelHeight.Text, acEngineering) ' Return the current value of the insertion point InsertionPoint = varPick End With 'calculate center point from input dblCenter(0) = CDbl(varPick(0)) + (dblLength / 2) dblCenter(1) = CDbl(varPick(1)) + (dblWidth / 2) dblCenter(2) = CDbl(varPick(2)) + (dblHeight / 2) 'draw the entity Set objEnt = ThisDrawing.ModelSpace.AddBox(dblCenter, dblLength, _ dblWidth, dblHeight) 'get part reference Set gpartref = ThisDrawing.ModelSpace.AddCustomObject("AcmPartRef") gpartref.Origin = varPick 'insert Profile Block InsertionPoint = varPick Set ProfileRef = ThisDrawing.ModelSpace.InsertBlock(InsertionPoint, "P+P", varPick(0), varPick(1), varPick(2), 0) 'update entity objEnt.History = True objEnt.Update ThisDrawing.Regen acActiveViewport Me.Show End Sub Quote
Lee Mac Posted February 27, 2009 Posted February 27, 2009 Also, is it meant to be "End Sub" at the end - again, just guessing Quote
hairyuga Posted February 27, 2009 Author Posted February 27, 2009 Forgot about Rotation Almost! Now I get an Invalid Z arguement! Quote
Lee Mac Posted February 27, 2009 Posted February 27, 2009 I don't know enough VBA to get you out of that one Maybe in LISP I could do it, but not VBA Quote
hairyuga Posted February 27, 2009 Author Posted February 27, 2009 No worries! Thanks for your help Quote
Lee Mac Posted February 27, 2009 Posted February 27, 2009 Just out of curiosity, why are you doing it in VBA? This task would be much easier to accomplish using LISP... Quote
hairyuga Posted February 27, 2009 Author Posted February 27, 2009 I want to learn VBA so I'm trying to accomplish it in that language but Iam new at this programming stuff. Quote
Lee Mac Posted February 27, 2009 Posted February 27, 2009 If you are just starting to use programming, I would avoid learning VBA as it is almost a dead language in terms of ACAD. See here: http://www.cadtutor.net/forum/showthread.php?t=33191 Quote
hairyuga Posted February 27, 2009 Author Posted February 27, 2009 Yes, I've read that thread. Right now, most programs in my office are written in VBA (before I got here), hence the need to learn it. Even if VBA dies, Autodesk will support it for years to come before they phase it out because of older users. Quote
Lee Mac Posted February 27, 2009 Posted February 27, 2009 I can see your reasoning, I just find that things can be accomplished easier and with a lot less coding in LISP Quote
dbroada Posted February 27, 2009 Posted February 27, 2009 VBA is my preferred choice of language. Possibly as I was trained in FORTRAN which isn't too dissimilar to BASIC which in turn isn't too dissimilar to VB which etc. Also I find it MUCH easier to read than LISP. There are some things you can't do in VBA but once you have a set of sub routine written it doesn't take too long to put it all together. Unfortunately I can't help here as our new IT policy severly limits my time around the forum at work and I don't have AutoCAD at home. Quote
Lee Mac Posted February 27, 2009 Posted February 27, 2009 I suppose its just what you get used to Dave, I have only really ever played around with LISP and so when I look at VBA, it just looks too complicated and I haven't got around to dissecting it and studying it as yet... Am I right in saying that Fortran was one of the first programming languages to be brought into existence? Quote
SEANT Posted February 27, 2009 Posted February 27, 2009 The InsertBlock method has this signature: RetVal = object.InsertBlock(InsertionPoint, Name, Xscale, Yscale, ZScale, Rotation [, Password]) Your code is trying to use the x, y, and z coordinates of the original .GetPoint call for the scale values. I suppose that may be what you want – but it would be out of the ordinary. The reason you are getting the “Invalid Z argument” is because the return from the .GetPoint probably has a z = 0, or maybe negative. Neither work with block insertion. Quote
dbroada Posted February 28, 2009 Posted February 28, 2009 Am I right in saying that Fortran was one of the first programming languages to be brought into existence? http://en.wikipedia.org/wiki/Fortranlooks that way. I thought I had been taught FORTRAN IV but looking at the dates it was probably a latter version. I learned sometime in the 70s. We were looking at getting a computer to do finite element analysis rather than getting the analysis done by a bureaux in London. At about the same time Commodore brought out their "PET" machine - 1k memory, tape drive tiny keyboard and built in BASIC language so I didn't use FORTRAN much and quickly became OK at BASIC. Quote
Lee Mac Posted February 28, 2009 Posted February 28, 2009 It still amazes me how much computers have evolved in such a short space of time... Thanks for the info Dave. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.