comcu Posted July 19, 2008 Posted July 19, 2008 I have the following code which i am trying to modify so it will select all objects on screen Public Sub TestSelectOnScreen() Dim objSS As AcadSelectionSet On Error GoTo Done With ThisDrawing.Utility '' create a new selectionset Set objSS = ThisDrawing.SelectionSets.Add("TestSelectOnScreen") '' let user select entities interactively objSS.SelectOnScreen '' highlight the selected entities objSS.Highlight True '' pause for the user .prompt vbCr & objSS.Count & " entities selected" .GetString False, vbLf & "Enter to continue " '' unhighlight the entities objSS.Highlight False End With Done: '' if the selection was created, delete it If Not objSS Is Nothing Then objSS.Delete End If End Sub i know you can filter for specif items eg circles and layers and then this will filter when you are selecting - example code below Sub Ch4_FilterBlueCircleOnLayer0() Dim sstext As AcadSelectionSet Dim FilterType(1) As Integer Dim FilterData(1) As Variant Set sstext = ThisDrawing.SelectionSets.Add("SS4") FilterType(0) = 0 FilterData(0) = "Circle" FilterType(1) = 8 FilterData(1) = "0" sstext.SelectOnScreen FilterType, FilterData End Sub but i am trying make the selection set select everything on the screen. I dont want the user to be forced to select all object as my code later on relies on all the blocks with a certain name. if all the blocks are not selected it cause problems with the code later plus it would make the overall coding run faster if it doesnt stop mid way to allow selection. can anyboby give me an example? i have searched help but coud not find anything? cheers, col. Quote
comcu Posted July 19, 2008 Author Posted July 19, 2008 answer: MyObjSS.Select acSelectionSetAll Quote
ML0940 Posted July 20, 2008 Posted July 20, 2008 Comcu, Here, let me help you a little further a long yet.. This is what you will want: MyObjSS.Select acSelectionSetAll, , , FilterType, FilterData Now, all the entities in the drawing that meet your filter criteria will be included in the selection set. It looks like you are trying to include all circles on layer 0, correct? Good Luck ML Quote
BIGAL Posted July 21, 2008 Posted July 21, 2008 A bit more help no need to select FilterDXFCode(0) = 0 FilterDXFVal(0) = "INSERT" SS.Select acSelectionSetAll, , , FilterDXFCode, FilterDXFVal For Cntr = 0 To SS.Count - 1 If SS.Item(Cntr).Name.Value = "SCHEDTXT" Then ie If searches all blocks for those with a particular name Quote
ML0940 Posted July 21, 2008 Posted July 21, 2008 BIGAL That is pretty interesting; Does the .value belong in there? Perhas you were programming in Excel? I use the value methos a lot when programming in Excel ML Quote
comcu Posted July 21, 2008 Author Posted July 21, 2008 ML, thank you for the help. BIGAL, I will try your code it looks good. thank you everyone. col Quote
ML0940 Posted July 21, 2008 Posted July 21, 2008 Hi Comcu Sure anytime There are a few different methods that you can use to achieve the same goal but BIGAL does look good. I tend to not use DXF codes but rather, I create my selection set and loop through the sset by entity type, then name of the entity. I don't think one is better then the other, it is just easier for me to work with. If you like, I can show you example of that method as well ML Quote
comcu Posted July 23, 2008 Author Posted July 23, 2008 ML, thank you i have just done a the type of thing you are describing, with help from this site!. where i have a block and i loop through the attributes, i am about to start writing a new code so i hope to implement the code myself as i think i now understand it. thank you for your help, cheers col Quote
ML0940 Posted July 23, 2008 Posted July 23, 2008 Hey Comcu, Glad to hear it; I like that, you took the intitave, that's great! I have posted quite a few posts with that method, you may have seen one of my examples while browsing. If you need any further help, just let me know Good luck! ML Quote
ML0940 Posted July 23, 2008 Posted July 23, 2008 So, did you do something like; For each ent in sset If typeof ent = acadblockreference then If type of ent = acadattribute then If att.name = "comcu" Then comcu.delete End if End if End if Next Ent Sorry, if the code is wrong, I was typing it on the fly here, but the loop part would look something like that. ML Quote
comcu Posted July 24, 2008 Author Posted July 24, 2008 ML, Yes it was of the same type of idea, For Each MyoEnt In MyObjSS If TypeOf MyoEnt Is AcadBlockReference Then Set MyBlockRef = MyoEnt dblBrefInPt = MyBlockRef.InsertionPoint dblRotation = MyBlockRef.Rotation Xaxis = .PolarPoint(OP, dblRotation, 1#) Yaxis = .PolarPoint(OP, pi / 2 + dblRotation, 1#) Set NewUCS = ThisDrawing.UserCoordinateSystems.Add(OP, Xaxis, Yaxis, "UCSfromRef") NewUCS.Origin = dblBrefInPt ThisDrawing.ActiveUCS = NewUCS myvaratt = MyBlockRef.GetAttributes For i = 0 To UBound(myvaratt) If myvaratt(i).TagString = "INFO_BLOCK_ID" Then myvaratt(i).TagString = "BLOCK_REF" myvaratt(i).Alignment = acAlignmentLeft myvaratt(i).StyleName = "Standard" myvaratt(i).Invisible = True myvaratt(i).height = 250# insertionPnt11() = .TranslateCoordinates(myvaratt(i).InsertionPoint, acWorld, acUCS, 0) insertionPnt11(0) = insertionPnt11(0) + 1048# ' insertionPnt11(1) = insertionPnt11(1) + 2900 myvaratt(i).InsertionPoint = .TranslateCoordinates(insertionPnt11, acUCS, acWorld, 0) myvaratt(i).Update End If Next End If Next The code above is just a extract of the overall thing. it is complete to the point of working but i believe i could slim it down and also improve it. i would be grateful of your opion on it and any tips you could give me to improve it as i am stillvery much a learner. i can post it at the minute but i will do so and hopefully you have time to have a look at it. cheers, Col. Quote
ML0940 Posted July 24, 2008 Posted July 24, 2008 Hey Col, I'm glad to see that I am not the only one up so late, I am actually doing some programming in Excel; it is something I have been wanting to get done for a while and have not had a chance until now to look at it. If your code is only a beginning, then I would say you are doing pretty dam good! OK, well, I need to be honest, I have used attributes a lot in the past but the need for me to work with them programmatically has never really come up; so without trying the code, I could not make any good suggestions; although if you have a specific problem, I can help you debug through it. Do you see why I prefer the typeof method? Again there is nothing wrong with using the dxf group filters, however, you then need to know what numbers represent what entity types etc. etc. With this method, for example, if you declared your variable MyBlockRef as AcadBlockReference You already have your entity type (AcadBlockReference) right in front of you; so we don't need to go looking for what dxf code = what entity type; it just makes sense to me. Also, you declared a variable for an Acadentity Dim MyoEnt as Acadentity Now that you have directed VBA to loop through each entity in the sset and find the entity type blockreference, you could also do this dblBrefInPt = MyoEnt.InsertionPoint, and so on So after each typeof ent that you filter for, the variable MyoEnt by default should equal that entity type, eliminating the need to explicitly set a reference, such as Set MyBlockRef = MyoEnt There is nothing at all wrong with this Set MyBlockRef = MyoEnt; especially if it helps you to better follow the code but I don't think it is necessary. If the variable MyoEnt is declared as an Acadentity, then it should pick up all of the methods and properties of the entity type that you instructed it to find in the loop. I used that same method to loop through all control types on a from once; that was pretty cool. So, for instance, if you wanted to find all list boxes on a form, you could apply the same methodology. Instead of Acadentity, you would likely need to declare a variable as Object, as controls are not Acadentities, so it would look something like this: Dim MyObj as Object For Each MyoObj In Userform1 (or whatever you name the form) If TypeOf MyoObj Is listbox Then listbox.width = 25 End if Next MyoObj Good job Col! Keep it going ML Quote
ML0940 Posted July 24, 2008 Posted July 24, 2008 Col, Also, don't quote me on this, but give it a try; If you declared your variable: Dim MyBlockRef as AcadBlockReference Then you may be able to get away with this If TypeOf MyoEnt Is AcadBlockReference Then dblBrefInPt = MyBlockRef.InsertionPoint No need for this: Set MyBlockRef = MyoEnt ML Quote
comcu Posted July 29, 2008 Author Posted July 29, 2008 ML, Thank you very much for the tips, as I said I am not great with VBA and only learning but I do understand (hopefully) your tips and will try and implant them in my code to help stream line. Thank you very much. Col Quote
ML0940 Posted July 29, 2008 Posted July 29, 2008 No Problem Col It looks like you are off to a great start. And there is ALWAYS more to learn If you need anymore help, just holler ML Quote
ML0940 Posted July 29, 2008 Posted July 29, 2008 Col One more good tip, if you do not know this already. Click on view, Locals Then when The Locals Window is open, click F8, that will start processing your code in the Locals Window. As you keep hitting F8, it will go through each step of your code and you will see precisely where it runs into problems, so that you know what and where to address it. I have also learned a lot just watching the code (in locals) as it goes through loops etc. It really helped me to understand how the code is processed, therefore, I think it helps you become better at coding as well. A lot of times in the past, I would come on the forums and ask a question, when all I needed to do was use locals to debug. It can be your best friend when coding in VBA ML Quote
comcu Posted July 29, 2008 Author Posted July 29, 2008 ML, thanks for that,. no i had not heard of the local window. i will look at that. Cheers. col Quote
ML0940 Posted July 29, 2008 Posted July 29, 2008 Cool! That wiill be your new best friend Col! ML Quote
johnalane Posted August 12, 2008 Posted August 12, 2008 Hi Guys I am new to the Forum Interesting post on Selection set...does anyone remember SSX.lsp ? ;;; Larry Knott Version 2.0 7/18/88 ;;; Carl Bethea & Jan S. Yoder Version 3.0 ;;; Enhancements to (ssx). ;;; 15 March 1990 We are using AutoCAD 2005 moving to 2008 end of month....SSX still works... Regards John SSX.LSP Quote
ML0940 Posted August 13, 2008 Posted August 13, 2008 Hi John I am not really a LISP programmer but I do use a little bit of LISP here and there. ssget was always a really good one for creating a quick sset at the command line. Here is a pretty cool example of where I combined ACAD with LISP If you run this macro from VBA, it will prompt you with an input box for the sset name. The reason I created it is because I like doing ssets sometimes that are not related to a programming task and I know I would not remember The LISP syntax. ML Sub CreateSSinCAD() Dim SsetName As String SsetName = InputBox("Enter Selection Set name and select your objects" & vbCrLf & vbCrLf & _ "Use the sset transparently with a modify command" & vbCrLf & "ie cp (enter) !ssetname") If SsetName > "" Then ThisDrawing.SendCommand "(setq " & (SsetName) & " (" & "ssget))" & vbCr End If End Sub Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.