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

Pick object or hit space bar

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
397 Views, 4 Replies

Pick object or hit space bar

how to translate this to dot net?
yes it's using acad com api but the vba type api call won't work in dotnet
so i think the question is valid here
'vba version
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As
Integer

Function checkkey(ByVal lngKey As Long) As Boolean

If GetAsyncKeyState(lngKey) Then

checkkey = True

Else

checkkey = False

End If

End Function

how to do this in dotnet?

Sub SamplePickObjectOrSpace()

Dim eKeyCode As System.Windows.Forms.KeyEventArgs

'Public Const VK_SPACEBAR As KeyEventArgs = New eKeyCode.KeyCode.Space



Dim dimension As AcadDimension = Nothing

Dim sPrompt As String = "Pick Dimension"

Dim vp As New Object

Try

m_acadDoc.Utility.GetEntity(dimension, vp, sPrompt)

Catch ex As Exception

'what do i do with ekeyCode.Space here?

End Try

End Sub



Thanks for any help, and before you direct me to the vba group, i've already
asked there ...

I've been trying various things but nothings working yet

for example:

Try

m_acadDoc.Utility.GetEntity(dimension, vp, sPrompt)

Catch ex As Exception

If GetAsyncKeyState(eKeyCode.KeyCode.Space) Then

MsgBox("Hit space bar")

End If

End Try

the error i get is

Access of shared member, constant member, enum member or nested type through
an instance; qualifying expression will not be evaluated.

mark
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

"mp" wrote in message
news:6307462@discussion.autodesk.com...
how to translate this to dot net?
yes it's using acad com api but the vba type api call won't work in dotnet
so i think the question is valid here
'vba version
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As
Integer

Function checkkey(ByVal lngKey As Long) As Boolean

If GetAsyncKeyState(lngKey) Then

checkkey = True

Else

checkkey = False

End If

End Function

how to do this in dotnet?

Sub SamplePickObjectOrSpace()

Dim eKeyCode As System.Windows.Forms.KeyEventArgs

'Public Const VK_SPACEBAR As KeyEventArgs = New eKeyCode.KeyCode.Space



Dim dimension As AcadDimension = Nothing

Dim sPrompt As String = "Pick Dimension"

Dim vp As New Object

Try

m_acadDoc.Utility.GetEntity(dimension, vp, sPrompt)

Catch ex As Exception

'what do i do with ekeyCode.Space here?

End Try

End Sub



Thanks for any help, and before you direct me to the vba group, i've already
asked there ...

I've been trying various things but nothings working yet

for example:

Try

m_acadDoc.Utility.GetEntity(dimension, vp, sPrompt)

Catch ex As Exception

If GetAsyncKeyState(eKeyCode.KeyCode.Space) Then

MsgBox("Hit space bar")

End If

End Try

the error i get is

Access of shared member, constant member, enum member or nested type through
an instance; qualifying expression will not be evaluated.

mark

to show how eKeyCode was declared i include the following:
ps entire sample is:
Sub SamplePickObjectOrSpace()

Dim eKeyCode As KeyEventArgs

'tried eKeyCode = New KeyEventArgs but get other error

Dim dimension As AcadDimension = Nothing

Dim sPrompt As String = "Pick Dimension"

Dim vp As New Object

Try

m_acadDoc.Utility.GetEntity(dimension, vp, sPrompt)

Catch ex As Exception

If GetAsyncKeyState(eKeyCode.KeyCode.Space) Then

MsgBox("Hit space bar")

End If

End Try

End Sub
Message 3 of 5
arcticad
in reply to: Anonymous

Here you can filter out what you want to select and tell if the command is canceled.

{code}
Sub GetSomething()
Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor()
Dim sOptions As New PromptEntityOptions(vbCr & "Select Dimension: ")
sOptions.SetRejectMessage(vbLf & "Select Dimension: ")
sOptions.AddAllowedClass(GetType(Dimension), False)

Dim sRes As PromptEntityResult = Nothing

While (True)
sRes = ed.GetEntity(sOptions)
If sRes.Status *Less Than* *Greater Than* PromptStatus.OK Then
If sRes.Status.ToString = "Cancel" Then
MsgBox("Cancel")
Exit While
End If
Else
Using db As Database = HostApplicationServices.WorkingDatabase()
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim myDWG As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Using lock As DocumentLock = myDWG.LockDocument
Dim myDim As Dimension = DirectCast(tr.GetObject(sRes.ObjectId, OpenMode.ForRead), Dimension)
MsgBox("You Picked " & TypeName(myDim))
End Using
End Using
End Using
End If
End While
End Sub
{code}
---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 4 of 5
Anonymous
in reply to: Anonymous

cool, thanks!
I'll see if that can live inside the existing vbnet project
I don't know if both com and net api code can be in same module...i'll find
out soon.
eventually i'd like to translate the whole thing over to c# anyway
so maybe this will serve as a first step
thanks
mark

wrote in message news:6308170@discussion.autodesk.com...
Here you can filter out what you want to select and tell if the command is
canceled.

{code}
Sub GetSomething()
Dim ed As Editor =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor()
Dim sOptions As New PromptEntityOptions(vbCr & "Select Dimension: ")
sOptions.SetRejectMessage(vbLf & "Select Dimension: ")
sOptions.AddAllowedClass(GetType(Dimension), False)

Dim sRes As PromptEntityResult = Nothing

While (True)
sRes = ed.GetEntity(sOptions)
If sRes.Status *Less Than* *Greater Than* PromptStatus.OK Then
If sRes.Status.ToString = "Cancel" Then
MsgBox("Cancel")
Exit While
End If
Else
Using db As Database =
HostApplicationServices.WorkingDatabase()
Using tr As Transaction =
db.TransactionManager.StartTransaction()
Dim myDWG As Document =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Using lock As DocumentLock = myDWG.LockDocument
Dim myDim As Dimension =
DirectCast(tr.GetObject(sRes.ObjectId, OpenMode.ForRead), Dimension)
MsgBox("You Picked " & TypeName(myDim))
End Using
End Using
End Using
End If
End While
End Sub
{code}
Message 5 of 5
arcticad
in reply to: Anonymous

Your Welcome.

Convert to C#
http://www.developerfusion.com/tools/convert/vb-to-csharp/

also at the end of the transaction you should still commit the transaction even if it's read only.

Using tr As Transaction = db.TransactionManager.StartTransaction()
tr.commit
End Using

commit is faster then dispose, I've been told.
---------------------------



(defun botsbuildbots() (botsbuildbots))

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