Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Member
gdaniels2
Posts: 8
Registered: ‎12-09-2009
Message 1 of 6 (359 Views)
Accepted Solution

ActiveX Selection Sets

359 Views, 5 Replies
02-07-2013 05:08 AM

Hi,

 

Has anyone tried retrieving an ActiveX selection set in AutoCAD 2013 (AutoCAD Architecture 64bit on Windows 7 is what I am using)?

 

Using a piece of LISP I got from the ADN developer site, it no longer works and gives this error....

 

Cannot invoke (command) from *error* without prior call to (*push-error-using-command*).
Converting (command) calls to (command-s) is recommended.

 

(defun c:erset (/ acApp acDoc selSets ss1)
   (vl-load-com)
   (setq acApp (vlax-get-acad-object))
   (setq acDoc (vla-get-activeDocument acApp))
   (setq selSets (vla-get-SelectionSets acDoc))
   (setq ss1 (vla-item selSets "TEST1"))
   (princ "Number of items in selection set TEST1 = ")
   (princ (vla-get-count ss1))
   (if (> (vla-get-count ss1) 0)
      (progn
         (alert "Erasing objects in selection set TEST1")
         (vla-erase ss1)
      ) ;progn
   ) ;if
   (princ)
) ;defun

 

Same with a similar one I found via google and have been using it for years. Unfortunatley my lisp is very basic so I have little idea if it an be fixed!

 

(defun c:getSset()
(vl-load-com)
(setq ss-vba (vla-item
(vla-get-selectionsets
(vla-get-activedocument
(vlax-get-acad-object)))
"SSforLisp"));; gets the ActiveX SS
(setq ss-lisp (ssadd));;creates a new ename-based ss
(vlax-for ent ss-vba
(ssadd (vlax-vla-object->ename ent) ss-lisp)
);;add each object's ename to the ename-ss
)

 

What about creating an AutoLisp selection set from .NET - is it possible, if so I would prefer to do that instead?

 

The goal is to create some objects in .NET (using activeX or managed code) and then have some way to access these objects via the command line I'm assuming they only way is using an AutoLISP selection set.

 

Many thanks,

 

Graham

MiTek Industries

 

 

Worked on my end with small changes:

 <LispFunction("MyLispFunction2")> _
Public Function VBNetFunction4(ByVal myLispArgs As ResultBuffer) As ResultBuffer
Dim rbfResult As ResultBuffer
Dim ed As Autodesk.AutoCAD.EditorInput.Editor
ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim prmptSelOpts As New PromptSelectionOptions()
prmptSelOpts.MessageForRemoval = vbLf + "Nothing selected"
prmptSelOpts.MessageForAdding = vbLf + "Select some objects:"
Dim prmptSelRes As PromptSelectionResult
prmptSelRes = ed.GetSelection(prmptSelOpts)
If prmptSelRes.Status <> PromptStatus.OK Then
rbfResult = New ResultBuffer(New TypedValue(5019))
Return rbfResult
End If
Dim selSet As SelectionSet
selSet = prmptSelRes.Value
ed.SetImpliedSelection(selSet)
rbfResult = New ResultBuffer( _
New TypedValue(CInt(5007), ed.SelectImplied.Value))
Return rbfResult
End Function

 In the command line I've typed

 

(setq sset (MyLispFunction2))

 

Another way with using pickfirstselectionset,

see what this function will retain for you:

 ' (selected objects)
<LispFunction("ListSelected")> _
Public Shared Function ListSelected(resBufIn As ResultBuffer) As ResultBuffer
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim blkId As ObjectId = db.BlockTableId
Dim resBufOut As New ResultBuffer()
If ed.SelectImplied.Value.Count = 0 Then
ed.WriteMessage(vbLf + "Works with previously selected objects only!")
resBufOut.Add(New TypedValue(CInt(LispDataType.Nil)))
Else
Using tr As Transaction = db.TransactionManager.StartOpenCloseTransaction()
Dim bt As BlockTable = TryCast(tr.GetObject(blkId, OpenMode.ForRead), BlockTable)
resBufOut.Add(New TypedValue(CInt(LispDataType.ListBegin)))
Dim sset As SelectionSet = ed.SelectImplied.Value
For Each sobj As SelectedObject In sset
resBufOut.Add(New TypedValue(CInt(LispDataType.ObjectId), sobj.ObjectId))
Next
resBufOut.Add(New TypedValue(CInt(LispDataType.ListEnd)))
End Using
End If
Return resBufOut
End Function
'' usage : (setq entlist (ListSelected))

 

Active Member
gdaniels2
Posts: 8
Registered: ‎12-09-2009
Message 2 of 6 (347 Views)

Re: ActiveX Selection Sets

02-07-2013 05:24 AM in reply to: gdaniels2

UPDATE...

 

I found a sample to transfer a selection set into lisp (using a VB.NET lisp function). Not tested it out yet but it looks promising, I think I need to transfer my activex objects into managed ones and then build a selection set and result buffer?

 

        <LispFunction("MyLispFunction2")> _
            Public Function VBNetFunction4(ByVal myLispArgs As ResultBuffer) As ResultBuffer
 
            Dim rbfResult As ResultBuffer
            Dim ed As Autodesk.AutoCAD.EditorInput.Editor
            ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
 
            Dim prmptSelOpts As New PromptSelectionOptions()
            Dim prmptSelRes As PromptSelectionResult
 
            prmptSelRes = ed.GetSelection(prmptSelOpts)
 
            If prmptSelRes.Status <> PromptStatus.OK Then
                rbfResult = New ResultBuffer(New TypedValue(5019))
                Return rbfResult
 
            End If
 
            Dim selSet As SelectionSet
            selSet = prmptSelRes.Value
            rbfResult = New ResultBuffer( _
                        New TypedValue(CInt(5007), selSet))
            Return rbfResult
        End Function

Active Member
gdaniels2
Posts: 8
Registered: ‎12-09-2009
Message 3 of 6 (338 Views)

Re: ActiveX Selection Sets

02-07-2013 06:04 AM in reply to: gdaniels2

Arrrghh!

 

Just tested it and it gives the same error message as the other examples!!!

 

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 6 (324 Views)

Re: ActiveX Selection Sets

02-07-2013 10:23 AM in reply to: gdaniels2

Worked on my end with small changes:

        <LispFunction("MyLispFunction2")> _
        Public Function VBNetFunction4(ByVal myLispArgs As ResultBuffer) As ResultBuffer

            Dim rbfResult As ResultBuffer
            Dim ed As Autodesk.AutoCAD.EditorInput.Editor
            ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor

            Dim prmptSelOpts As New PromptSelectionOptions()
            prmptSelOpts.MessageForRemoval = vbLf + "Nothing selected"
            prmptSelOpts.MessageForAdding = vbLf + "Select some objects:"
            Dim prmptSelRes As PromptSelectionResult

            prmptSelRes = ed.GetSelection(prmptSelOpts)

            If prmptSelRes.Status <> PromptStatus.OK Then
                rbfResult = New ResultBuffer(New TypedValue(5019))
                Return rbfResult

            End If

            Dim selSet As SelectionSet
            selSet = prmptSelRes.Value
            ed.SetImpliedSelection(selSet)
            rbfResult = New ResultBuffer( _
                        New TypedValue(CInt(5007), ed.SelectImplied.Value))
            Return rbfResult
        End Function

 In the command line I've typed

 

(setq sset (MyLispFunction2))

 

Another way with using pickfirstselectionset,

see what this function will retain for you:

        '   (selected objects)    
        <LispFunction("ListSelected")> _
        Public Shared Function ListSelected(resBufIn As ResultBuffer) As ResultBuffer
            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor
            Dim blkId As ObjectId = db.BlockTableId
            Dim resBufOut As New ResultBuffer()
            If ed.SelectImplied.Value.Count = 0 Then
                ed.WriteMessage(vbLf + "Works with previously selected objects only!")
                resBufOut.Add(New TypedValue(CInt(LispDataType.Nil)))
            Else
                Using tr As Transaction = db.TransactionManager.StartOpenCloseTransaction()
                    Dim bt As BlockTable = TryCast(tr.GetObject(blkId, OpenMode.ForRead), BlockTable)
                    resBufOut.Add(New TypedValue(CInt(LispDataType.ListBegin)))
                    Dim sset As SelectionSet = ed.SelectImplied.Value
                    For Each sobj As SelectedObject In sset
                        resBufOut.Add(New TypedValue(CInt(LispDataType.ObjectId), sobj.ObjectId))
                    Next
                    resBufOut.Add(New TypedValue(CInt(LispDataType.ListEnd)))
                End Using
            End If
            Return resBufOut
        End Function
        '' usage : (setq entlist (ListSelected))

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Member
gdaniels2
Posts: 8
Registered: ‎12-09-2009
Message 5 of 6 (316 Views)

Re: ActiveX Selection Sets

02-07-2013 11:03 AM in reply to: Hallex

Worked like a charm thanks!

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 6 of 6 (311 Views)

Re: ActiveX Selection Sets

02-07-2013 11:25 AM in reply to: gdaniels2

Glad to hear that,

Kind regards,

Cheers :smileyhappy:

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.