Maxelkat Posted June 27, 2012 Posted June 27, 2012 I want to create a Visual Basic program that will open a particular AutoCAD file, replace a particular block with another one from a particular location (with position and scale of the new block matching the one being replaced), and save the altered file in a particular location. Is what I'm attempting remotely possible? Quote
dbroada Posted June 27, 2012 Posted June 27, 2012 I have never been able to use VB to do this but I do use VB to build a script file that runs within AutoCAD to do so. As your tack sounds simple I would just write a script file without the VB bit unless you want to run this on a lot of drawings. Alternatively you can write a VBA routine with AutoCAD (or you could, it is an option on newer versions) to run within an open drawing. Certainly what you have described is easily achieved with VBA. Quote
Maxelkat Posted June 27, 2012 Author Posted June 27, 2012 Cheers Dave, Actually my colleague will be attacking the VB side of things. I think it'll be some sort of form that will lead the program to the right drawing, and make the right block replacement, hence the need for VB. I sort of know how to do the AutoCAD bit, but I'm not sure how they work together. Knowing that it should be possible helps. Elliott Quote
dbroada Posted June 27, 2012 Posted June 27, 2012 Form driven from VB is the bit I couldn't get to work but I know others have done it so it is possible. I just took the easy route. Quote
Jeff H Posted June 27, 2012 Posted June 27, 2012 If by 'Visual Basic' you mean VB.NET then yes, not enough knowledge to comment on VBA. Quote
BlackBox Posted June 27, 2012 Posted June 27, 2012 To the best of my limited understanding of Visual Basic for Applications (VBA), yes this is possible; just be aware that VBA is no longer supported by Microsoft, and is being killed off through attrition. While I know that VB.NET can also perform this task, IMO, the simplest solution (i.e., least amount of code), is to either write a Script (SCR), or to code yourself a small Visual LISP routine which employs ObjectDBX to programmatically perform the tasks stated in the OP. My $0.02 Quote
Bill Tillman Posted June 28, 2012 Posted June 28, 2012 just be aware that VBA is no longer supported by Microsoft, and is being killed off through attrition. That's what I keep hearing yet just a few days ago I heard the M$ will be supporting VB6 through the lifecycle of Windows 8. I'm working on several projects using VB.NET and VBA in Excel. Today as I looked up some information on the MSDN site the article I read had a single paragraph written in italics which reminded the reader that the information enclosed would soon be obselete and that I should pursue a method in the .NET arena. So I did. The trouble is the docs for VB.NET are lacking, cryptic, and otherwise very difficult to digest. My 2¢ worth. Quote
BlackBox Posted June 28, 2012 Posted June 28, 2012 That's what I keep hearing yet just a few days ago I heard the M$ will be supporting VB6 through the lifecycle of Windows 8. ... You'll love this thread then: VBA7 and C# scripting? Quote
BlackBox Posted June 28, 2012 Posted June 28, 2012 Also worthy of note... There is a difference between supporting VBA, and simply allowing it to live on. As I stated, it (VBA) is no longer supported (unless they come out with VBA7!), and _will_ die off through attrition one day (... it may take them 50 years, but by Golly they'll kill it off!). Quote
btraemoore Posted July 2, 2012 Posted July 2, 2012 I threw this together from some stuff that i already have written. it may need some tweeking. Sub your_BLK_name() Dim gpCode(1) As Integer Dim dataValue(1) As Variant Dim SS_your_BLK_name As AcadSelectionSet Dim i As Integer Set SS_your_BLK_name = ThisDrawing.SelectionSets.Add("SS_your_BLK_name") gpCode(0) = 0: dataValue(0) = "INSERT" gpCode(1) = 2: dataValue(1) = "name of old block" SS_your_BLK_name.Select acSelectionSetAll, , , gpCode, dataValue Dim BScale(2) As Double Dim BCoord() As Long Dim Cur_Blk as AcadBlockReference For i = 0 To SS_your_BLK_name.Count - 1 Set Cur_Blk = SS_your_BLK_name.Item(i) If Cur_Blk.Name = "name of old block" Then BScale(0) = Cur_Blk.XScaleFactor BScale(1) = Cur_Blk.YScaleFactor BScale(2) = Cur_Blk.ZScaleFactor BCoord() = Cur_Blk.InsertionPoint End If Next i If SS_your_BLK_name.Count > 0 Then SS_your_BLK_name.Erase Dim BlockObj As AcadBlockReference Set BlockObj = ThisDrawing.ModelSpace.InsertBlock(BCoord, "new block name", BScale(0), BScale(1), BScale(2), 0) End Sub 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.