Adding object to Selection Set by WorkSpace

Adding object to Selection Set by WorkSpace

RalphBrown99
Advocate Advocate
882 Views
8 Replies
Message 1 of 9

Adding object to Selection Set by WorkSpace

RalphBrown99
Advocate
Advocate

 

Hi:

 

I have a pice of code that select MText in my drawing. It looks that it select the MText in ALL my drawing and I am interested to choose the MText that is in the Model Space only.

 

The piece of code that I have is:

 

'Adding a Selection set in the drawing

Set objSS = ThisDrawing.SelectionSets.Add("TestSelectionSetOperator")
       
        'Using 4 filters to store in objSS -Selection Set- MText which is located in the Layer Text_MSpace

 

        ReDim intCodes(3): ReDim varCodeValues(3)
       
        'Set codes and values - intended for clarity
        intCodes(0) = -4:   varCodeValues(0) = "<and"
        intCodes(1) = 0:           varCodeValues(1) = "MText"
        intCodes(2) = 8:           varCodeValues(2) = "Text_MSpace"
        intCodes(3) = -4:   varCodeValues(3) = "and>"

        
        'Filter the objects
       
        objSS.Select acSelectionSetAll, , , intCodes, varCodeValues

 

       'how to add a criteria to choose the MText that is in ONLY in my model space?.

 

 

Thanks

 

 

Rafael

0 Likes
Accepted solutions (1)
883 Views
8 Replies
Replies (8)
Message 2 of 9

Alfred.NESWADBA
Consultant
Consultant
Accepted solution

Hi,

 

>> and I am interested to choose the MText that is in the Model Space only

Look at the 410 code:

   intCodes(0) = 0:           varCodeValues(0) = "MText"
   intCodes(1) = 8:           varCodeValues(1) = "Text_MSpace"

   intCodes(2) = 410:       varCodeValues(2) = "Model"

 

(you don't need the <and  .... and> in this case)

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 9

RalphBrown99
Advocate
Advocate

 

 

Hi Alfred:

 

By the way...where are you? Your piece of code is working. I have another question anyway, where is possible to get the list of codes so I can filter whatever object like work spaces, layers, drawing objects etc. I am aware that I can not ask you every 5 minutes for specific code number.

 

Thanks

 

 

Rafael

0 Likes
Message 4 of 9

Ed__Jobe
Mentor
Mentor

The codes are known as DXF (Drawing eXchane Format) codes and can be found in the Developer Guide. Look in Help for the dxf reference.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 9

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> By the way...where are you? 

==> currently close to >>>there<<<  😉

 

>> where is possible to get the list of codes

Besides of the DXF-manual my favorite LISP-command is this

(entget (car (entsel)))

Typing that into the command line (and start it) lets me select an entity and shows me then the code-pairs of the object. If you don't know what code is needed for modelspace then draw a line in modelspace from 0,0 to 10,10 and also in paperspace in a layout, then use my command for these both lines and compare the output. The value-pair with 410 is then different.

 

Command: (entget (car (entsel)))
Select object: ((-1 . <Objektname: 7ffff706a60>) (0 . "LINE") (330 . <Objektname: 7ffff7039f0>) (5 . "68E") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbLine") (10 0.0 0.0 0.0) (11 10.0 10.0 0.0) (210 0.0 0.0 1.0))

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 6 of 9

RalphBrown99
Advocate
Advocate

 

 

Hi Alfred:

 

Thanks in advance for your collaboration. Now I have problems with my AcadSelectionSet I mean, trying to debbug the code has created a problem in the AutoCAD-VBA programs. Everytime that I run the program is running worse due -I think- I have created several Selection Sets and now the code do not capture in this object a single CAD entity.

 

It is there a way to clean this selection set from the AutoCAD memory so I can run my memory several times and debug the macro properly?

 

Thanks

 

 

Rafael

0 Likes
Message 7 of 9

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

I don't know what makes your code crashing currently, you have not shown the line and not the message of the error.

Just as a guess if it'd this line:

   Set objSS = ThisDrawing.SelectionSets.Add("TestSelectionSetOperator")

Then you have the problem that you can only add a selectionset with a name once to the list of the current selectionsets. If you try to add a selectionset with the same name (that already exists) a second time then your code crashes.

You can therefor use these lines instead.

   On Error Resume Next

   Set objSS = ThisDrawing.SelectionSets.Add("TestSelectionSetOperator")

   If Err.Number <> 0 then

        'then a selectionset with this name already exists

        Set objSS = ThisDrawing.SelectionSets.Item("TestSelectionSetOperator")

        objSS.clear  

   End If

   On Error Goto 0

 

If that guess was wrong, then please "what line" and "what is the error-message" you get the exception.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 8 of 9

RalphBrown99
Advocate
Advocate

 

 

Hi Alfred:

 

I am wondering of you have an idea how to change the settings for either Dimension Styles and Multileader Styles using VBA.

 

In my case I have captured a value but I do not know how to change values based in this number. I want to set up

-Base line Spacing

-Exend Beyond Lines

-Offset from origin

 

etc etc

 

I want to do the same with a Multi Leader Style

 

Thanks in advance for your cooperation

 

Rafael

0 Likes
Message 9 of 9

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

allow me the following statement: "new question - new thread"!

It's easier for all the future visitors then to find their answers and if you write "Hi Alfred" then it may be others knowing how to help don't answer (as they are not asked). 😉

 

As a first way to got: create a new drawing, create two dimenstion-styles (with a different value that you search then), then start VBA and look into these two dim-style-properties to see the different value. Tha's the way how I go if I don't know the name of a property.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes