I am trying to add points to a point group. The problem that I am having is that creating a StandardPointGroupQuery will overwrite the point numbers already in the group. How do I just ADD to the existing point numbers.
I was thinking of getting all the point numbers and building that back into the new query but I am having no luck with that. Any help would be greatly appreciated.
Public Sub CogoPointNoDisplay() 'Get the current document and database Dim docEd As Editor = Active.Editor Dim curDb As Database = Active.Database Dim civDoc As CivilDocument = Active.CivilDocument Dim cmdloop As Boolean = True Try 'Start command loop Do While cmdloop 'Start selection options Dim acSSPrompt As New PromptEntityOptions(vbLf & "Select a COGO Point to set to _No Display: ") acSSPrompt.SetRejectMessage(vbLf & "Invalid Selection. Selected item is not a COGO point. Please select again." & vbLf) acSSPrompt.AddAllowedClass(GetType(CogoPoint), True) 'Set selection set Dim acSSet As PromptEntityResult = docEd.GetEntity(acSSPrompt) 'If selection is a cogo point If acSSet.Status <> PromptStatus.OK Then Return End If 'Start the transaction Using acTrans As Transaction = curDb.TransactionManager.StartTransaction() 'Set dbobject and open for write Dim acdbObj As Autodesk.AutoCAD.DatabaseServices.DBObject = acTrans.GetObject(acSSet.ObjectId, OpenMode.ForWrite) 'Set and cast point Dim acCogoPoint As CogoPoint = TryCast(acdbObj, CogoPoint) 'Get point number Dim acCogoPointNumber As String = acCogoPoint.PointNumber.ToString() 'Get _No Display point group Dim pointGroupId As ObjectId = civDoc.PointGroups.Item("_No Display") Dim pointGroup As PointGroup = TryCast(pointGroupId.GetObject(OpenMode.ForWrite), PointGroup) '----------------------------------------------------------------------------------------- Dim existPoints As String = pointGroup.GetPointNumbers.ToString() 'Set new query parameters Dim standardQuery As StandardPointGroupQuery = New StandardPointGroupQuery() standardQuery.IncludeNumbers = existPoints & ";" & acCogoPointNumber 'Set query pointGroup.SetQuery(standardQuery) 'Update point group pointGroup.Update() '----------------------------------------------------------------------------------------- 'Save the changes and dispose of the transaction acTrans.Commit() End Using Loop Catch ex As Exception 'Intentionally left out End Try docEd.Regen() End Sub
You should probably move the updating of the PG out of the loop. Collect a list of the Point Numbers to add to the PG, then use the PG.GetQuery() method. Test to see if the Query type is a custom query, if so notify the user that it cannot be edited (at least it wasn't editable in the past, I haven't checked recently). Cast it to a StandardPointGroupQuery then get the ExcludeNumbers property, run through the list of numbers to add to the PG and remove any found in the Exclude list and add the excluded numbers back query.ExcludeNumbers = excludednumbers. Then create new list for numbers, add the PG array from PG.GetPointNumbers(), run through your collected point numbers you want to add, check if the PG already includes any point numbers, if not then add that number to the new list. Next, set the IncludeNumbers to that updated list. Finally, set the PG Query to the modified query.
You may want to have a function to create a ranged list of strings so adjacent numbers will become 1-6,8-34,40,42-44, etc. See a post I made yesterday with such a function in lisp.
WOW! Thank you Jeff.
OK, let me digest this and take a stab at it. But the jist of it is:
1.) Get the new point numbers
2.) Get the existing included and excluded point numbers
3.) Create new query with existing and new and excluded point numbers
4.) Update group
Right? That is what I thought the approach would be, I was having an issue trying to get the existing numbers from the PG.GetPointNumbers. It is type UIntiger.
OK, so here is where I am at:
Here is the modified code so far:
Public Sub CogoPointNoDisplay() 'Get the current document and database Dim docEd As Editor = Active.Editor Dim curDb As Database = Active.Database Dim civDoc As CivilDocument = Active.CivilDocument Try 'Create a typedvalue array to define the filter criteria Dim acTypValAr(0) As TypedValue acTypValAr.SetValue(New TypedValue(DxfCode.Start, "AECC_COGO_POINT"), 0) 'Assign the filter criteria to a selectionfilter object Dim acSelFtr As New SelectionFilter(acTypValAr) 'Start cogo point selection prompt option Dim promptSelectionOptions As New PromptSelectionOptions promptSelectionOptions.MessageForAdding = (vbLf & "Select COGO Points to ADD to the _No Display point group: ") promptSelectionOptions.MessageForRemoval = (vbLf & "Select COGO Points to REMOVE from the selection set: ") 'Get prompt selection results Dim cogoPointPromptSelectionResult = docEd.GetSelection(promptSelectionOptions, acSelFtr) 'Set selection set Dim cogoPointSelectionSet As SelectionSet = cogoPointPromptSelectionResult.Value 'If selection are cogo points If cogoPointPromptSelectionResult.Status = PromptStatus.OK Then 'Start the transaction Using acTrans As Transaction = curDb.TransactionManager.StartTransaction() Dim selectedCogoPointNumbers As New List(Of String) For Each selectedCogoPoint In cogoPointSelectionSet 'Set dbobject and open for write Dim acdbObj As Autodesk.AutoCAD.DatabaseServices.DBObject = acTrans.GetObject(selectedCogoPoint.ObjectId, OpenMode.ForRead) 'Set and cast point Dim acCogoPoint As CogoPoint = TryCast(acdbObj, CogoPoint) 'Get point number Dim acCogoPointNumber As String = acCogoPoint.PointNumber.ToString() selectedCogoPointNumbers.Add(acCogoPointNumber) Next Dim cogoPointsToAdd As String = String.Join(",", selectedCogoPointNumbers) '--------------------------------------------------------------------------------------------------------------------- 'Get _No Display point group Dim pointGroupId As ObjectId = civDoc.PointGroups.Item("_No Display") Dim pointGroup As PointGroup = TryCast(pointGroupId.GetObject(OpenMode.ForWrite), PointGroup) 'Get existing point group query/information Dim getExistQuery As PointGroupQuery = pointGroup.GetQuery Dim existQuery As StandardPointGroupQuery = TryCast(getExistQuery, StandardPointGroupQuery) Dim includedNumbers As String = existQuery.IncludeNumbers.ToString() Dim excludedNumbers As String = existQuery.ExcludeNumbers.ToString() 'Set new query parameters Dim newStandardQuery As StandardPointGroupQuery = New StandardPointGroupQuery() newStandardQuery.IncludeNumbers = includedNumbers & "," & cogoPointsToAdd newStandardQuery.ExcludeNumbers = excludedNumbers 'Set query pointGroup.SetQuery(newStandardQuery) 'Update point group pointGroup.Update() 'Save the changes and dispose of the transaction acTrans.Commit() End Using End If Catch ex As Exception ''Initiate error message box End Try docEd.Regen() End Sub
@David_Prontnicki wrote:
OK, so here is where I am at:
- You should probably move the updating of the PG out of the loop. I removed the loop and went with PromptSelectionOptions with a filter instead. Works better that way anyway. Good
- Collect a list of the Point Numbers to add to the PG, then use the PG.GetQuery() method. Created a New List(of String) for the selected point numbers. Used the GetQuery to get existing information. Good
- Test to see if the Query type is a custom query, if so notify the user that it cannot be edited (at least it wasn't editable in the past, I haven't checked recently). I cant seem to figure out how to check if there is a custom query. I don't see how to access that. Any help would be great. Use GetType(), or I think you can TryCast()
- Cast it to a StandardPointGroupQuery then get the ExcludeNumbers property, run through the list of numbers to add to the PG and remove any found in the Exclude list and add the excluded numbers back query.ExcludeNumbers = excludednumbers. I "cast'ed" the GetQuery to a Standard and extracted the included and excluded point numbers to a string.
- Then create new list for numbers, add the PG array from PG.GetPointNumbers(), run through your collected point numbers you want to add, check if the PG already includes any point numbers, if not then add that number to the new list. Next, set the IncludeNumbers to that updated list. Finally, set the PG Query to the modified query. I created a NEW query with StandardQuery including the original points and the new points to add. No, you don't need to create a new StandardQuery. Use the one you got from the PointGroup.
- You may want to have a function to create a ranged list of strings so adjacent numbers will become 1-6,8-34,40,42-44, etc. See a post I made yesterday with such a function in lisp. I saw your LiSP from yesterday and defiantly want to take you up on this suggestion as it makes complete sense. But I cant figure out how to convert that LiSP to VB as I have not done LiSP in years. Is this something you would be will to help me out with? I'd help, but VB to me is about the same as lisp for you I imagine. I can do lisp and c#, but VB is not something I am good with...I can read it, mostly, but writing in it is another thing.
Here is the modified code so far:<snip>
@David_Prontnicki wrote:
I was having an issue trying to get the existing numbers from the PG.GetPointNumbers. It is type UIntiger.
A Uint is just a positive integer. The CogoPoint.PointNumber is also a Uint...
Can't find what you're looking for? Ask the community or share your knowledge.