TheSwamp

Code Red => .NET => Topic started by: Peter Jamtgaard on June 02, 2010, 08:30:47 AM

Title: acedGetEnv and acedSetEnv in VB.NET
Post by: Peter Jamtgaard on June 02, 2010, 08:30:47 AM
I did a search on the site and couldn't find a reference to acedGetEnv and acedSetEnv

Comments?

Peter

Code: [Select]
mports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports System.Runtime.InteropServices 'for DllImport()
Imports System.Security
Imports System.Text.StringBuilder
Imports System.Reflection.Assembly


Public Class vbvlClass
    ' Use P/Invoke for acedGetEnv

    ' Use P/Invoke for acedGetEnv

    <System.Security.SuppressUnmanagedCodeSecurity(), DllImport("acad.exe", _
    CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="acedGetEnv")> _
    Private Shared Function acedGetEnv(ByVal strEnvironmentName As String, ByVal stbReturnValue As System.Text.StringBuilder) As Integer
    End Function

    ' Use P/Invoke for acedSetEnv

    <System.Security.SuppressUnmanagedCodeSecurity(), DllImport("acad.exe", _
    CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="acedSetEnv")> _
    Private Shared Function acedSetEnv(ByVal strEnvironmentName As String, ByVal stbNewValue As System.Text.StringBuilder) As Integer
    End Function


    '______________________________________________________________________________________________________________________
    '
    ' Get and Set environment variables using th P/Evoke
    '______________________________________________________________________________________________________________________

    <LispFunction("GetEnvironment")> _
    Public Shared Function GetEnvironment(ByVal rbfEnvironmentName As ResultBuffer) As ResultBuffer
        Dim rbfReturn As New ResultBuffer
        Dim arrEnvironmentName As TypedValue() = rbfEnvironmentName.AsArray
        Dim strEnvironmentName As String = arrEnvironmentName(0).Value.ToString
        Dim stbReturn As New System.Text.StringBuilder(1024)
        Try
            acedGetEnv(strEnvironmentName, stbReturn)
            rbfReturn.Add(New TypedValue(&H138D, stbReturn.ToString))
        Catch Ex As Exception
            rbfReturn.Add(New TypedValue(&H138D, "Error " & Ex.Message))
        End Try
        Return rbfReturn
    End Function
    '______________________________________________________________________________________________________________________
    '
    ' Overload GetEnvironment function to accept and return strings
    '______________________________________________________________________________________________________________________

    Public Shared Function GetEnvironment(ByVal strEnvironmentName As String) As String
        Dim stbReturn As New System.Text.StringBuilder(2048)
        Try
            acedGetEnv(strEnvironmentName, stbReturn)
            Return stbReturn.ToString
        Catch Ex As Exception
            Return "Error " & Ex.Message
        End Try
    End Function
    '______________________________________________________________________________________________________________________
    '
    ' SetEnvironment function to accept and return result buffers
    '______________________________________________________________________________________________________________________

    <LispFunction("SetEnvironment")> _
    Public Shared Function SetEnvironment(ByVal rbfEnvironmentName As ResultBuffer) As ResultBuffer
        Dim rbfReturn As New ResultBuffer
        Try
            Dim arrEnvironmentName As TypedValue() = rbfEnvironmentName.AsArray
            Dim strEnvironmentName As String = arrEnvironmentName(0).Value.ToString
            Dim strNewValue As String = arrEnvironmentName(1).Value.ToString
            Dim stbNewValue As New System.Text.StringBuilder(1024)
            stbNewValue.Append(strNewValue)
            acedSetEnv(strEnvironmentName, stbNewValue)
            rbfReturn.Add(New TypedValue(&H138D, stbNewValue.ToString))
        Catch Ex As Exception
            rbfReturn.Add(New TypedValue(&H138D, "Error " & Ex.Message))
        End Try
        Return rbfReturn
    End Function

    '______________________________________________________________________________________________________________________
    '
    ' Overload SetEnvironment function to accept and return strings
    '______________________________________________________________________________________________________________________

    Public Shared Function SetEnvironment(ByVal strEnvironmentName As String, ByVal strNewValue As String) As String
        Try
            Dim stbNewValue As New System.Text.StringBuilder(2048)
            stbNewValue.Append(strNewValue)
            acedSetEnv(strEnvironmentName, stbNewValue)
            Return "OK"
        Catch Ex As Exception
            Return "Error " & Ex.Message
        End Try
    End Function
End Class
Title: acedGetEnv and acedSetEnv in VB.NET
Post by: Kerry on June 02, 2010, 08:59:04 AM
I did a search on the site and couldn't find a reference to acedGetEnv and acedSetEnv

Comments?
Peter


Yep

http://www.theswamp.org/index.php?topic=20237.msg362446#msg362446

http://www.theswamp.org/index.php?topic=22942.msg275966#msg275966

and from Augi
http://forums.augi.com/showthread.php?t=109055&highlight=acedSetEnv
Title: Re: acedGetEnv and acedSetEnv in VB.NET
Post by: Peter Jamtgaard on June 02, 2010, 07:05:44 PM
Where is that dialog search form?

The one I used shown below is from the Search on the toolbar, and selecting the advanced button.

Peter
Title: Re: acedGetEnv and acedSetEnv in VB.NET
Post by: Kerry on June 02, 2010, 07:11:20 PM

try this ..
Title: Re: acedGetEnv and acedSetEnv in VB.NET
Post by: Kerry on June 02, 2010, 07:17:47 PM


... and for anyone following ..
You don't need to use the advanced search.
The normal search will search the current forum section, so if you are somewhere in the .NET forum search will find the reference if it exists.
... at least that's been my experience.
Title: Re: acedGetEnv and acedSetEnv in VB.NET
Post by: Keith™ on June 02, 2010, 09:11:56 PM
I am a bit perplexed ... it appears that you are defining new functions to set read environment variables (presumably from lisp) when you could simply use getenv and setenv. If you are using it for some other purpose then by all means carry on ...
Title: Re: acedGetEnv and acedSetEnv in VB.NET
Post by: Peter Jamtgaard on June 02, 2010, 09:30:31 PM
Daniel 

(and other swamp creatures)

I just add the LISPFunction to test the code.

I thought it would be useful for .net to set the values for the environment and lisp variables.

What am I doing?

Right now I am more interested in exploring the different entry points of the acad.exe and other arx autocad dll's

I found some old delphi code that shows some of the variabe types for the various entry points in acad.exe.

I have been trying to see if I can get any of them to work.

Have any of you got the acedEvalDiesel entry point to work?

I have it running, but am having trouble getting the values out.

Also I want to say that a good portion of the code I have posted is from other sources, and I do not take credit for inventing them, just maybe translating them and getting them to work in vb.net.

I do re-write the code to make the code VERY similar to the other examples to help myself and any others to learn from them.

I by no means want to take the credit from the original developers.

On the AUGI, Autodesk, ADN, VBForums, ....

I always figure that forums are here to share code, and help others to learn to program.

I very much appreciate all of your suggestions and code samples.

I also want you to know that when I find something useful or cool,
I share it on these groups almost immediately.

Sometimes I may copy similar programs from one forum to another.

If this group has other rules of forum etiquette please let me knnow.

Thanks again.

Peter
Title: Re: acedGetEnv and acedSetEnv in VB.NET
Post by: It's Alive! on June 02, 2010, 10:13:30 PM
Peter,

That's what this place is all, about learning from each other and building upon code others have posted. Feel free to use anything I've posted anyway you like. There are instances where the author has put significant effort into their posts, out of respect, its proper to acknowledge their efforts with a comment in the code I.e.
Code: [Select]
// Based on the fine work of Tony the Tiger
...
Title: Re: acedGetEnv and acedSetEnv in VB.NET
Post by: It's Alive! on June 02, 2010, 10:56:55 PM
or in my case.

//This is a fix-up of the crap Dan posted


 :lol:
Title: Re: acedGetEnv and acedSetEnv in VB.NET
Post by: Kerry on June 02, 2010, 11:03:28 PM

I had

Can't argue with that !!

ready to post
... before you added the last   :-D