PrevSelectedObjects not working?


#1

Hi,

in a script I want to get the object that was used by dimangle.
But it doesn’t return the object:

'--------------------------------------------------
Rhino.Command “_DimAngle”

arrObjects = Rhino.PrevSelectedObjects

If IsArray(arrObjects) Then
msgbox "Is an array"
Else
msgbox "No array"
End If
’--------------------------------------------------

In my tests it seem to work because I had an arc selected outside the script before.
In reality it doesn’t work.

What could I do?

Thanks,
-C-H-A-R-L-E-S-


#2

No idea vor hint?


#3

Hi Charles,

I have no knowledge of VBscript, but weren’t you suppose to declare the new variable (arrObjects) first?

	Rhino.Command "_DimAngle"
	
	Dim arrObjects
	arrObjects = Rhino.PrevSelectedObjects

	If IsArray(arrObjects) Then
		msgbox "Is an array"
	Else
		msgbox "No array"
	End If

(Rajaa Issa) #4

You needed to use “LastCreatedObjects” rather than “PrevSelectedObjects”:
arrObjects = Rhino.LastCreatedObjects

Does that work?


#5

I use lastcreatedobjects to get the created dimension afterwards and that works as expected.
I must get the arc that was selected for dimangle.
And the arc just exists, it was created not as last object.

Other ideas?

Charles


#6

Assuming the arc was pre-selected for the Rhino.Command to work,

arrObjects = Rhino.SelectedObjects, may work


#7

Hey Charles,

I don’t think you’re going to make that work… If you do the operation manually, the same thing happens, SelPrev does not select the arc either. And DimAngle does not work with a pre-selected arc unfortunately.

SelPrev only works under certain specific circumstances, for the most part it’s pretty useless…

–Mitch


#8

OK, I lied… the following bit of trickery works:

Option Explicit
Call TestDimAngle()
Sub TestDimAngle()
	Dim arcID
	arcID=Rhino.GetObject("Select an arc to dimension",4,True,True)
	Call Rhino.Command("_DimAngle _SelID "&arcID)
End Sub

You always have access to the arc object as it is stored in the variable arcID…

–Mitch


#9

I love it when you’re lying, scriptmaster!

Here:

Option Explicit
    
    'Script version 2013-12-04
    
    Rhino.AddStartupScript Rhino.LastLoadedScriptFile
    Rhino.AddAlias "DimArcLen", "_NoEcho _-Runscript (DimArcLen)"
    
    'DimArcLen
    
    sub DimArcLen()
    
    	Dim dblLength 
    	Dim DimID
    	Dim strLength
    	Dim arcID
    
    	SetLocale("en-us")
    	
    	Call Rhino.UnselectAllObjects
    	
    	arcID = Rhino.GetObject("Select an arc to dimension", 4, True, True)
    	If Not Rhino.IsCurve(arcID) Then Exit Sub
    	
    	Call Rhino.Command("_DimAngle _SelID " & arcID)
    	If rhino.LastCommandResult <> 0 Then Exit Sub
    	
    	DimID = Rhino.LastCreatedObjects()(0)
    	If Not Rhino.IsAngularDimension(DimID) Then Exit Sub
    			
    	dblLength = Rhino.CurveLength(arcID)
    	
    	strLength = "L="
    	strLength = strLength & formatnumber(dblLength, 2)
    	strLength = strLength & "mm"
    
    	Rhino.DimensionUserText DimID, strLength
    
    end sub

Thank you very much Mitch!!!

Q: How do you get the syntax highlighting into the message?

-C-H-A-R-L-E-S-


#10

Check this topic. Use backticks for code block, instead of preformatted text.


#11
Msgbox "Got it!"