See the top rated post in this thread. Click here

Page 5 of 5 FirstFirst 12345
Results 41 to 46 of 46

Thread: sysvar changed reactor

  1. #41
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: sysvar changed reactor

    You cannot evaluate any string containing a LISP expression that
    includes entity names or selection sets.
    "(progn (setq ss (ssget))(if (> (sslength ss) 0)(setq ent (ssname ss 0))))"

    Works OK and returns the LISP objectID of the first item of the selection set as a resultbuffer (list).

    "(progn (setq XXXX (entlast))(foo XXXX))"

    Would work OK.

    I did find a couple of statements that are invalid though, so I guess I cannot evaluate ANY statement.

    "(vlax-get-acad-object)"
    "(vla-get-activedocument (vlax-get-acad-object))"

    both would return nil because they do not have valid LISP objectID's or entity names.

    Peter
    Last edited by peter; 2010-06-01 at 01:05 PM.
    AutomateCAD

  2. #42
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: sysvar changed reactor

    Tony,

    I agree that .NET cannot create a entity name or LISP selectionset itself, but .NET Handles and LISP objectID's are the same.

    I can convert .NET handles to entitynames easily. Similar for selection sets. See below.

    If strObjectHandle is an .NET Object Handle

    EvaluateLISP("(foo (objectIDToEName " & strObjectHandle & " ))")

    Simlarly for Selection Sets.

    No problemo.

    Peter

    Code:
    (defun objectIDToObject (intObjectID)
     (vla-objectIDToObject 
      (vla-get-activedocument (vlax-get-acad-object))
      intObjectID
     )
    )
    
    (defun ObjectIDToEName (intObjectID)
     (vlax-vla-object->ename
      (vla-objectIDToObject 
       (vla-get-activedocument (vlax-get-acad-object))
       intObjectID
      )
     )
    )
    (vl-load-com)
    Also

    Without using acedInvoke(), you cannot call a LISP function from
    .NET,
    You can use the acedEvaluateLISP entry point also.
    Last edited by peter; 2010-06-01 at 06:47 PM.
    AutomateCAD

  3. #43
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: sysvar changed reactor

    This is not all of my code but an example of using the acedEvaluateLISP extry point for the others who are monitoring this thread. I am sure you know this code too.

    I wanted to post this code first.

    Code:
    Imports Autodesk.AutoCAD.DatabaseServices
    Imports Autodesk.AutoCAD.Runtime
    Imports System.Runtime.InteropServices 'for DllImport()
    Imports System.Security
    
    
    Public Class vbvlClass
        ' Use P/Invoke for acedEvaluateLISP
    
        <System.Security.SuppressUnmanagedCodeSecurity(), DllImport("acad.exe", _
        CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Cdecl, EntryPoint:="?acedEvaluateLisp@@YAHPB_WAAPAUresbuf@@@Z")> _
        Private Shared Function acedEvaluateLISP(ByVal strLISPExpression As String, ByRef intHandle As IntPtr) As Integer
        End Function
        '______________________________________________________________________________________________________________________
        '
        ' Overload of the EvaluateLISPExpression function to accept ResultBuffer as Argument
        '______________________________________________________________________________________________________________________
    
        <LispFunction("EvaluateLisp")> _
        Public Shared Function EvaluateLispExpression(ByVal rbfLISPExpression As ResultBuffer) As ResultBuffer
            Dim rbfReturn As New ResultBuffer
            Dim arrLispExpression As TypedValue() = rbfLISPExpression.AsArray
            Return EvaluateLispExpression(arrLispExpression(0).Value.ToString)
        End Function
    
        Public Shared Function EvaluateLispExpression(ByVal strLISPExpression As String) As ResultBuffer
            Dim rbfObject As IntPtr = IntPtr.Zero
            Dim rbfReturn As New ResultBuffer
            Try
                acedEvaluateLISP(strLISPExpression, rbfObject)
                If (rbfObject <> IntPtr.Zero) Then
                    rbfReturn = CType(DisposableWrapper.Create(GetType(ResultBuffer), rbfObject, True), ResultBuffer)
                    Return rbfReturn
                Else
                    rbfReturn.Add(New TypedValue(&H138D, "Error"))
                End If
            Catch ex As System.Exception
                rbfReturn.Add(New TypedValue(&H138D, "Catch Error"))
                Return rbfReturn
            End Try
            Return Nothing
        End Function
    End Class
    AutomateCAD

  4. #44
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: sysvar changed reactor

    Tony,

    Assuming that the .NET app could use a string builder to transform a .net selectionset into a string with all of the .net handles and spaces between them... this lisp function could convert it to a lisp selection set.

    It really doesn't have to be this long but I allowed the list, a string with parenthesis on both ends or just a strings with the ObjectID's and spaces between them to be passed.

    I had write it and test it first to respond.

    I am sure I could condense it before I would be done with it.

    No problemo.

    Peter


    Code:
    (defun ListOfObjectIDsToSSet (lstOfObjectIDs / intCount ssReturn X)
     (if (= (type lstOfObjectIDs) 'STR)
      (if (= (substr lstOfObjectIDs 1 1) "(")
       (setq lstOfObjectIDs (eval (read (strcat "'" lstOfObjectIDs))))
       (setq lstOfObjectIDs (eval (read (strcat "(quote (" lstOfObjectIDs "))"))))
      )
     )
     (mapcar '(lambda (intObjectID)
               (if ssReturn
                (setq ssReturn (ssadd (objectIDToEname intObjectID) ssReturn))
                (setq ssReturn (ssadd (objectIDToEname intObjectID)))
               )
              )
              lstOfObjectIDs
     )
     ssReturn
    )
    AutomateCAD

  5. #45
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: sysvar changed reactor

    Tony,

    I guess you probably figured out my trick you mentioned earlier.

    I do not have .NET evaluate the LISP expression. the Invoke entry point only passes the lisp expression to a loaded lisp function as a string. Then the lisp routine evaluates it. That way I can have LISP revise the returning values to better interface with .net like converting a vla-object to an ename, a selection set to a list of objectID's etc...

    I have not finished that part of the lisp code, but it really is not difficult to do.

    (eval (read "what ever lisp expression you can think of"))

    I am sure you can see the advantages of having LISP evaluate LISP. right?

    You tell me what you think is the best way to have values returned from lisp that vb.net would digest the easiest.

    Peter
    AutomateCAD

  6. #46
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: sysvar changed reactor

    The fact is that there is little need to call LISP from .NET,
    I guess we agee to disagree with this statement.

    I have never promoted "not learning .net", I think all autocad customizers should learn it.

    I only advocated that in order to help make a transition that lisp programmers need to:

    First learn to program new lisp functions using .net (learning .net)

    Second learn to program in .net while still being able to use all of their legacy code written in LISP.

    Third be able to develop in either language based on the requirements of the application.

    The right tool for the job.

    Until you asked me I didn't plan on passing selection sets or entity names between the languages. You said it wasn't possible. I showed you it was. I can also create the result buffers in reverse and include all of the selection set information too. It is all easy to do.

    Another easier way would to create selection set in .net then use the (ssget "p") in lisp and transfer all of the subentity information.

    <<Moderator edited to conform to forum guidelines>>

    I repsect your right to your opinion... You will not change my mind.

    I would appreciate it if you would respect mine.

    Peter
    Last edited by Ed Jobe; 2010-06-05 at 10:05 PM.
    AutomateCAD

Page 5 of 5 FirstFirst 12345

Similar Threads

  1. Replies: 22
    Last Post: 2010-04-09, 03:03 AM
  2. Replies: 19
    Last Post: 2009-12-22, 09:58 PM
  3. Replies: 1
    Last Post: 2009-08-14, 01:05 PM
  4. FILLET Sysvar?
    By gfreddog in forum AutoCAD General
    Replies: 12
    Last Post: 2008-02-26, 04:47 PM
  5. vlr-sysvar-reactor doesn't fire
    By pnorman in forum AutoLISP
    Replies: 1
    Last Post: 2005-04-12, 03:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •