.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Selecting entities in AutoCAD 2009 from C# Visual Studio 2008

25 REPLIES 25
Reply
Message 1 of 26
Elie911
868 Views, 25 Replies

Selecting entities in AutoCAD 2009 from C# Visual Studio 2008

Hi,

in my graduation project, I need to prompt the user from a C# Windows Application to select a line so I can access its properties .
It seems that no one in my university knows a solution for this problem .
Can I find it here ??

Plz , I really need your help .

Using AutoCAD 2009 and Visual Studio 2008 .

Best Regards ...
25 REPLIES 25
Message 21 of 26
Elie911
in reply to: Elie911

Plz someone help me , I'm really running out of the project delivery date ....
Message 22 of 26
Anonymous
in reply to: Elie911


This thread is more and more out of topic of this
NG (.NET API NG), since your are doing VBA now. Well, see some comments inline
anyway.

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
hello
, here is the code I used for filling a multicolumn listbox from an excel
workbook :





Private Sub UserForm_initialize()



size=2>




Dim app As excel.Application

Dim wbook As
excel.Workbook

Dim wsheet As excel.Worksheet

Dim rg As
excel.Range



Set app = excel.Application


this line should be (notice the "New"
keyword):


Set app=New excel Application


app.Visible=True


size=2>

size=2>


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
If I do Excel automation, I alway make it visible
so that user know something is going on and if my code run int error, I do not
end up with a hidden Excel app left behind in Task Manager.

 

Of course you can try
GetObject(,"Excel.Application) to see if there is already an Excel app
instance running, so that you do not have to "New" it. Make sure you have
proper error handling

 

size=2>


Set wbook =
app.Workbooks.Open("C:\Materials.xlsx")

Set wsheet =
wbook.Worksheets(1)

Set rg = wsheet.Range(A1, D107)



Dim
iCol As Integer

iCol = 2

Dim iRow As Integer



For
iRow = 1 To 10 Step iRow + 1

ListBox1 = wsheet.Cells(iRow,
1).Value

Next


 


you need to make sure to close the workbook and
quit the Excel app


Set rg=Nothing


Set wsheet=Nothing


wbook.Close


Set wbook=Nothing


app.Quit



End Sub



but an error is appearing :




Run-time error '1004':

Method 'Range' of object
'_worksheet' failed



plz help !!!


 


Have you step through the code in debugging? You
should be easily identify the offending line of
code.

Message 23 of 26
Elie911
in reply to: Elie911

Thank you for your help , but with the code you suggested an error is still occuring :



Run-time error '1004':

Method 'Range' of object'_Worksheet' failed



and the cause after debugging is the line :

Set org = owst.Range(A1, D107)
Message 24 of 26
norman.yuan
in reply to: Elie911

Shouldn't

owst.Range(A1,D107)

be

owst.Range("A1:D10")

?

or be

owst.Range(Cells(1,1),Cells(4,107))

?
Message 25 of 26
norman.yuan
in reply to: Elie911

sorry, for

owst.Range(Cells(1,1),Cells(4,107))

I meant:

owst.Range(Cells(1,1),Cells(107,4))
Message 26 of 26
Elie911
in reply to: Elie911

Now the line :



Set org = owst.Range(Cells(1, 1), Cells(107, 4))



is causing the error : Method 'Cells' of object '_Global' failed



and the line :



ListBox1 = wsheet.Cells(iRow, 1).Value





is causing the error : object needed



Best regards ...

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost