Only allow NODE selection

Only allow NODE selection

David_Prontnicki
Collaborator Collaborator
1,610 Views
4 Replies
Message 1 of 5

Only allow NODE selection

David_Prontnicki
Collaborator
Collaborator

I have a pick point prompt and I want to limit it to allow only the selection of a node. How would I do this. I am in VB.net.

 

Thanks,

David

0 Likes
1,611 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor

You use system variable OSMODE to control Object Snap when selecting. SO, you would have code like:

 

Dim oldVal As Object=Application.GetSystemVariable("OSMODE")

Try

    Application.SetSystemVariable("OSMODE", 8) '' 8 is the object snap mode for NODE

    '' Ask your user to select here

Finally

    Application.SetSystemVariable("OSMODE", oldVal)

End Try

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 5

David_Prontnicki
Collaborator
Collaborator

Hi Norman, Thank you for the response. I should have been more specific. I have what you suggested in place already and it only allows the node onsap. But I can still click where there inst a node. 

 

My program places labels, i want to limit the user to selecting only a node; any other point should not be excepted. As it stands and also with your suggestion, it will set the NODE osnap current, but a user can still pick a random spot on the screen. I want to allow for the label to be placed on a NODE only.

 

Thank you!

0 Likes
Message 4 of 5

norman.yuan
Mentor
Mentor

Ah, I know what you mean. 

Setting osnap mode only allows AutoCAD to provide visual hint for where is suggested position to pick, but user may still pick anywhere he/she wants. In the case of yours, besides setting "OSMODE" system variable, you can also use Editor.Snap() method in your code to locate the actual location of a Node. Something like:

 

Dim oldVal As Object=Application.GetSystemVariable("OSMODE")

Dim nodePt as Point3d

Try

    Application.SetSystemVariable("OSMODE", 8) '' 8 is the object snap mode for NODE

    Dim res = _editor.GetPoint(vbcr & "Select a node:") '' 

    If res.Status == PromptStatus.OK Then

        '' It is not guaranteed that user selects the location precisely

        '' but we can expect user click at the location, or very close to the location

        '' so, we use the selected point to find/snap to the nearest node point

        nodePt = _editor.Snap("NOD", res.Value)

        '' You may need further validation code to make sure the point is what you want here

    End If

Finally

    Application.SetSystemVariable("OSMODE", oldVal)

End Try

 

As you can see, after Editor.Snap() call, it should reasonably expect the point at target (NODE, or END, or whatever) is returned. If the drawing is very crowded at the expected location, you may want to zoom in enough first, or even freeze unwanted layers so the Snap() call can snap to the NODE/END... correctly. You may also need code after Snap() call to validate the returned point with your specific rules. But in most cases, setting OSMODE and calling Editor.Snap() would be good enough.

 

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 5

David_Prontnicki
Collaborator
Collaborator

Thank you Norman, I will try this tonight or over the weekend. I'll let you know how it goes.

I really appreciate the help!

0 Likes