Author Topic: Point Selection  (Read 6374 times)

0 Members and 1 Guest are viewing this topic.

cadpro

  • Guest
Point Selection
« on: June 18, 2011, 01:41:12 PM »
Hi,

I'm actually looking to edit an attribute in a block that contains 2 closed rectangular polylines, and one attribute each inside each rectangle. When the user picks anywhere inside the rectangle, it should detect that particular attribute in the block. I couldn't think of a solution to it. Is it possible to get the area around the picked point, detect the rectangle, and then detect the attribute in the rectangle? For this to work, should the block be exploded programmatically? Please help.
 
Thanks

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Point Selection
« Reply #1 on: June 18, 2011, 02:32:34 PM »
I wouldn't go through the process of exploding the block. Once upon a time, I had a lisp routine that did something similar.

Consider translating the selected point to the UCS of the block, then programmatically find the rectangle that encompasses that point. Once you know that, you can then select the appropriate attribute and update as needed.

Presumably, the attributes have different tags and are easily identifiable.

Another way would be to simply map the block and filter the point based on the selected location, but that wouldn't be scalable and would break if the block was changed. For example, Presume that the block has attribute A at 1,1 and attribute B at 4,1 and there are two rectangles represented by 0,0:2,2 and 3,0:5,2 with a base of 0,0.

Now, lets say the user picks inside of 11,12 and the block is inserted at 10,10. You would determine that the actual point in relation to the block would be 1,2 and subsequently you would know that attribute A is the one to update.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

cadpro

  • Guest
Re: Point Selection
« Reply #2 on: June 18, 2011, 02:46:16 PM »
Thanks for the reply.

Well, every rectangle in the block reference has a set of attributes and only one of these attributes has to be changed which I can get using the attribute tag.

Could you give me a bit of a sample code of what you have explained?

Thanks

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Point Selection
« Reply #3 on: June 18, 2011, 02:49:37 PM »
Unfortunately, I don't have anything handy and to be honest, I've not done alot of .net programming with AutoCAD.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Point Selection
« Reply #4 on: June 18, 2011, 03:08:28 PM »
Here a little something not as good as Kieth explained but using promptNestedEntity to change attributes.

Just run it and click on a attribute,

Code: [Select]
   <CommandMethod("ChangeAtts")> _
        Public Shared Sub ChangeAtts()
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor

            Using trx As Transaction = db.TransactionManager.StartTransaction()
                Try

                    Dim pner As PromptNestedEntityResult

                    Do
                        pner = ed.GetNestedEntity("Select Attribute")

                        If pner.Status <> PromptStatus.OK Then
                            Exit Do
                        End If

                        If Not pner.ObjectId.ObjectClass.Name = "AcDbAttribute" Then
                            Continue Do
                        End If

                        Dim attref As AttributeReference = trx.GetObject(pner.ObjectId, OpenMode.ForRead)

                        Dim pso As New PromptStringOptions(vbLf & "Enter new Attributr value ")
                        pso.AllowSpaces = True

                        Dim res As PromptResult = ed.GetString(pso)

                        If res.Status <> PromptStatus.OK Then
                            Exit Do
                        End If

                        Dim strvalue As String = res.StringResult
                        attref.UpgradeOpen()
                        attref.TextString = strvalue
                        db.TransactionManager.QueueForGraphicsFlush()

                    Loop While pner.Status = PromptStatus.OK
                    trx.Commit()

                Catch ex As Autodesk.AutoCAD.Runtime.Exception

                    ed.WriteMessage((vbLf + ex.StackTrace & vbLf) + ex.Message)
                End Try
            End Using
        End Sub


The code is basically from here with  little changes http://www.theswamp.org/index.php?topic=35184.0

cadpro

  • Guest
Re: Point Selection
« Reply #5 on: June 18, 2011, 05:28:54 PM »
Thanks very much for the code.

This is what I want, but that works only when there is already an attribute value. If the attribute is empty, I cannot pick the attribute to change. Hence I'm thinking of a way to capture the area around a point that the user picks, which is where I'm stuck. Once I get the area around and inside the rectangle of the picked point, I can loop thought the entities and find the right attribute.

Thanks
« Last Edit: June 18, 2011, 05:51:09 PM by cadpro »

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Point Selection
« Reply #6 on: June 18, 2011, 05:34:28 PM »
Well, every rectangle in the block reference has a set of attributes and only one of these attributes has to be changed which I can get using the attribute tag.
Thanks

Are you sure the tag will always be the same and unique compared to any other tags?
If so I am not sure why you want to do the extra effort, I can see letting the user select which block insertion.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Point Selection
« Reply #7 on: June 18, 2011, 05:51:22 PM »
If I were going to attempt this in lisp, I would simply create a point in memory at a distance of X from the selected point (direction is unimportant in a closed polygon) then attempt to find a block reference using those two points as a crossing selection.

Once you have the block reference, you can easily get the attribute that you wish to edit based on the user selected point in relationship to the insertion point of the block reference.

Logically flowing through the steps would make this a much simpler task for you.

1) User selects point
2) create test point at X units in the Y direction
3) create a selection set of all block references matching the target block using a crossing between PT1 and PT2
4) extract the insertion point of the selected block reference.
5) calculate the location of the user selected point in relation to the insertion point
6) using the two closed polygons in the block table for that block reference, determine if the adjusted point is inside of RECT1 or RECT2
7) select appropriate attribute and update

Now that is a fair simplification of the process, and you will need to ensure you error check for the existence of the block reference before attempting to work on it .. if you don't find the block reference using a programmatic crossing selection (entities will need to be visible), you may need to simply select all matching block references in the drawing programmatically, filter them for the one closest to the selected point, translate the user point to the UCS of the block reference and then determine if the point falls within RECT1 or RECT2

I wish I could explain it as clearly as I can see it in my mind.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

cadpro

  • Guest
Re: Point Selection
« Reply #8 on: June 18, 2011, 05:56:16 PM »
I have attached a sample of the drawing with two rectangles and two attributes each in each rectangle in a block.

cadpro

  • Guest
Re: Point Selection
« Reply #9 on: June 18, 2011, 05:58:29 PM »

Are you sure the tag will always be the same and unique compared to any other tags?
If so I am not sure why you want to do the extra effort, I can see letting the user select which block insertion.

Yes, the tags will always be the same, with a number depending on the number of rectangles it contains

cadpro

  • Guest
Re: Point Selection
« Reply #10 on: June 18, 2011, 06:14:24 PM »
Keith, thanks very much for the explanation.

I will try to code that out.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Point Selection
« Reply #11 on: June 18, 2011, 08:20:47 PM »
To throw some ideas out there if the rectangles are polylines you can get the GeometricExtents of polylines.
You can use the blocktransform of the blocktablerecord to get the transformation.

Extents3d has a AddPoint which you could add the picked point and use Extents3d.IsEqualTo to see if it changed and the attribute inside Poistion would also not change it if enclosed.

I will stop here and maybe Keith or one of the handful of guys that are real good at math with the translations, matrix, etc.. probably have a better idea or tell you whats wrong with this approach.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Point Selection
« Reply #12 on: June 19, 2011, 01:20:55 AM »
To throw some ideas out there if the rectangles are polylines you can get the GeometricExtents of polylines.
You can use the blocktransform of the blocktablerecord to get the transformation.

This is pretty much the approach I would take

Extents3d has a AddPoint which you could add the picked point and use Extents3d.IsEqualTo to see if it changed and the attribute inside Poistion would also not change it if enclosed.

I am not sure this would be necessary as long as you have the polyline extents and the transformation of the selected point. A simple check of the values would be sufficient to verify the location is within the boundary.

I will stop here and maybe Keith or one of the handful of guys that are real good at math with the translations, matrix, etc.. probably have a better idea or tell you whats wrong with this approach.

Nothing wrong with the approach ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

cadpro

  • Guest
Re: Point Selection
« Reply #13 on: June 19, 2011, 10:07:55 AM »

I will stop here and maybe Keith or one of the handful of guys that are real good at math with the translations, matrix, etc.. probably have a better idea or tell you whats wrong with this approach.


Could any of you experts give me a start on this code please?

Is GeometricExtents the four coordinates of the rectangle?

Thanks
« Last Edit: June 19, 2011, 04:52:58 PM by cadpro »

cadpro

  • Guest
Re: Point Selection
« Reply #14 on: June 20, 2011, 06:27:17 AM »
I did get the GeometricExtentsj and can compare with the MinPoint and MaxPoint of the polyline. But how do I get the nearest entity of the picked point?