I am new here today...searching a code in internet for following problem.
I have a drawing in AutoCAD2005.
I have written a VisualBasic program finding an Appropriate dwg files in Particular folders coz you people know how our Explorer works..in tree form...clicking clicking and so on till we need our particular folder..so inorder to minimize the time program works using command buttons and lists all the dwgs in Listview.
now i choose a dwg file in Listview ( i mean its a small drawing which should be inserted in opened drawing ). and click the Button INSERT.
now task is this dwg file which is been selected in Listview shold be inserted in opened autocad drawing.
Please can anybody help me how to write this code for this Button Insert..
You should be able to ShellExecute the dwg file so it opens with its associated program which is Autocad.
Code:
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Const SW_HIDE As Long = 0
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWMINIMIZED As Long = 2
Private Sub Command1_Click()
ShellExecute Me.hwnd, "open", "C:\Users\Public\Test1.dwg", vbNullString, "C:\", SW_SHOWNORMAL
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Yes AutoCad does support VBA but that wont help in this situation. He has written his app to populate his listview with the dwg files. He wants to select one and open it either in a new AutoCad instance of in an existing instance.
If its new instance then my posted code will do it. If its an existing instance then will AutoCad load the dwg in the existing instance as a second window or will it create a secondary instance altogether?
Then there is the question if he wants the dwg to be added to the canvas in an existing drawing. This will be more difficult as most of us dont have autocad so unsure how that would be done.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
I've got an older copy Acad2000, I was waiting for Singoi to post again to confirm what he/she wants. There is a built in dialog that can be invoked from AutoCads command line, it Inserts one drawing into another but it does not use a treeview. I imagine it would be pretty straight forward to make a friendlier version using the VBA component.
If it is the case that the drawing should be inserted into another drawing then the insertion point, and scale parameters might also be important.
But it sounds like this is desired and being done already in VB 6 so it should be just starting auocad and passing those arguments to do an actual insert as you mentioned. Either way I think we can get it solved once we hear back
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
seems to be interesting when i go through my forum..haha..
well..my problem is not yet solved..i am attaching a small JPEG how my window looks like.there is a Listview which shows my dwgs in particular folder.
now i already opened a drawing (for example allias.dwg) and on my second monitor i open my program and i select going throough all my command buttons to my destination folder..and now i select my dwg here in listview.
i click insert.
now my task is this selected dwg should be inserted either as block or as normal dwg in Allias.dwg
now i dont need exact point where its supposed to be inserted..but should get inserted..later i can move this to the position where i need depending on the free space available.
I hope my friends have understood my task..
hoping a response from you.
I have been doing this project with different other features since weeks...and wanna include this feature also in my project..so i have continued doing..
as we know that our servers are full of different harddisks with different names like C,D,F bla bla bla...similarly we got loads of disks and loads of folders where users are going on searching for required dwg hours and hours..
this made me think to make this feature so that it will be easy and less time consuming in making tasks faster.
please help me in making this code for this button INSERT...
please please pleaseeeeeeeee....searching since days for this code..
I dont have AutoCad so I would say you will have to either google for now or wait until Milk is back online as he has an older copy of AutoCad to work with
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
If I remember correctly from past posts, AutoCad does have a form of VBA, so this sounds more like a job for that than for Visual Basic 6.
I know when I install AutoCAD 2000 5 or 6 years years ago some of the AutoCAD applications were made with VB6 because it overite a lot of the VB ocx's with older versions, I wasn't to pleased.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
To my mind it would make a lot more sense to write an AutoCad helper program from within AutoCad it self, giving you full access to the Blocks and Drawings collections.
That said the command line window (Txt:"Marin" Cls:"Afx:400000:8:10011:10:0" for ACAD2000) is always open and accepts the WM_PASTE messages.
Copying this to the clipboard and sending the WM_PASTE message to the command window should insert <<The Blocks Path>> at 0,0,0. Scaled 1:1 in X and Y and rotated to 0 degrees. All relative to the WCS not the current UCS.
Code:
-insert
<<The Blocks Path>>
0,0,0
1
1
0
I guess your code will need to find all the AutoCad windows which are open, if more than one it will need to know which one. Check to see if a drawing is open. If a drawing is open then look for the Command Line child window. Copy the commands to the clipboard. Send the WM_PASTE message to the Command Line Window. Job Done.
If I remember correctly the command console can be set up on a different monitor.
It might be possible to link up between your App and Autocad on a lower level but I don't know how.
Edit: Have a look at Fazi's Sendmessage blaster, it's useful for working out whats going on window wise.
Dim acadApp As acadapplication
Dim acDWG As AcadDocument
Dim block As String
Dim inspoint As Object
'Dim Scale As Double
block = ListView1.SelectedItem
Try
acadApp = trycast(marshal.getactiveobject("autocad.application"), acadapplication)
if typeof (acadApp) is acadapplication Then
If acadApp.Documents.Count > 0 Then
acDWG = acadApp.ActiveDocument
inspoint = acDWG.Utility.GetPoint(, "select Insertion point:")
acDWG.ModelSpace.InsertBlock(inspoint, block, scale, scale, scale, 0.0#)
Else
Msgbox("AutoCAD doesn't have any Drawings open.", MsgBoxStyle.Exclamation)
End If
catch ex As exception
EndTry
End Sub
but getting errors..not functioning.
I need the file which user selects in Listview inserted in opened drawing. Attaching a JPEG File...User has selected a file in Viewlist box..now presses Insert..this following File should get inserted in Opened Drawing...
Pleaseeeeeeeeeeeeeee friends..loosing hope coz not able to find the right code which can work...
The code you post looks like .net but the form you post looks like VB6, what language are you using?
Have you tried the DDE version I posted? If you give it a valid block path, it can insert it at the specified coordinate at the specified scale and rotation it the current active drawing. Is that not what you want?
Dim acadApp As AcadApplication
Dim acDWG As AcadDocument
Dim block As String
Dim inspoint() As Object
Dim Scale1 As Double
block = ListView1.SelectedItem
Scale1 = 1#
'On Error GoTo errhandler:
On Error GoTo NoAutocad
Set acadApp = GetObject(, "AutoCAD.Application")
On Error GoTo 0
If TypeOf acadApp Is AcadApplication Then
If acadApp.Documents.Count > 0 Then
Set acDWG = acadApp.ActiveDocument
inspoint = acDWG.Utility.GetPoint(, "Select Insertion point:")
Dim blk As AcadBlockReference
Set blk = acDWG.ModelSpace.InsertBlock(inspoint, block, Scale1, Scale1, Scale1, 0#)
Else
MsgBox ("AutoCAD doesn't have any Drawings open.")
End If
Else
End If
Exit Sub
NoAutocad:
MsgBox "Autocad Not Started!", vbCritical
End Sub
i have changed the code...as above..
i am using Excel VBA Editor...starting will be in Excel and then VBA...using VB6...coz i dont have VB6 installed in my computer and my superiors dont wanna invest money on it..but want the program to be success..
cant be against them..and i want to make this programm run..
i am using Excel VBA Editor...starting will be in Excel and then VBA...using VB6...coz i dont have VB6 installed in my computer and my superiors dont wanna invest money on it..but want the program to be success..
Although it might be a little late in the game, if you need VBA code, then the question needs to be in the Office Development section.