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

Help with this active directy code and passing variables to lisp

1 REPLY 1
Reply
Message 1 of 2
Anonymous
220 Views, 1 Reply

Help with this active directy code and passing variables to lisp

What I need is to get the current users active directry organization unit
and pass that as a variable to LiSP
Ideally I would just load an arx or dll and have a lisp variable to use in a
lisp routine


using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using System.DirectoryServices;
using System.Data;
using System.Text;

public class HelloWorld
{

public static DirectoryEntry getDEBySearchFilter(string filter)
{
try
{
DirectoryEntry rootEntry = new
DirectoryEntry("LDAP://DOMAIN.net/DC=DOMAIN,DC=net");
DirectorySearcher searcher = new DirectorySearcher(rootEntry);
searcher.Filter = filter;
return searcher.FindOne().GetDirectoryEntry();
}
catch (NullReferenceException)
{
throw new ApplicationException("ERROR: " + filter + ": not in
Active Directory");
}
}

[Autodesk.AutoCAD.Runtime.CommandMethod("cmdado")]
public void HelloCommand()

string a =
System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split('\\')[1];
DirectoryEntry de =
getDEBySearchFilter("(&(objectCategory=person)(samAccountName=" + a + "))");
string ouchild = de.Parent.Name.Remove(0, 3);
string ouparent = de.Parent.Parent.Name.Remove(0, 3);
string domain = de.Parent.Parent.Parent.Name.Remove(0, 3);

acadApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage(domain
+ "\\" + ouparent + "\\" + ouchild);
acadApp.UpdateScreen();
}
}



--
Dave
1 REPLY 1
Message 2 of 2
kosak956
in reply to: Anonymous

David,
In AutoCAD 2007 there is a new Function to use for passing
arguments to C# and returning values to VLISP.
You can find the information in the ObjectARX Developer's guide
under "Defining Methods That Can Be Called From AutoLISP"

Managed applications can define methods so that they can be called by AutoLISP applications. To do so, the managed application tags the desired method with the Autodesk.AutoCAD.Runtime.LispFunction attribute. This attribute can be used in the same places and has the same properties as the CommandMethod attribute. The key difference lies in the signature form to which LispFunction may be applied. LispFunction is valid only for methods of the form

public ResultType MyHandler(ResultBuffer args) {
...
}
where ResultType can be any one of the following types:

int
double
TypedValue
ResultBuffer
string
Point2d
Point3d
bool
void
ObjectId
SelectionSet
The Autodesk.AutoCAD.Runtime.LispDataType enumeration defines .NET identifiers that represent the data types passed through AutoLISP ResultBuffer arguments.

For instance, the following C# code defines an AutoLISP-callable “Hello World” method:

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
...
[LispFunction("c:helloworld")]
public void hw(ResultBuffer args)
{
Editor ed =
Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage('\n' + "Hello World!" + '\n');
}


I hope this helps

Regard
Konstantin

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