.NET

Reply
*David Allen
Message 1 of 2 (71 Views)

Help with this active directy code and passing variables to lisp

71 Views, 1 Replies
07-14-2006 08:48 AM
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
Active Contributor
konstantinos.sakellaris
Posts: 43
Registered: ‎07-26-2001
Message 2 of 2 (71 Views)

Re: Help with this active directy code and passing variables to lisp

08-15-2006 09:18 AM in reply to: *David Allen
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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!