|
|
|
Area calculation (text) placed into shape
|
|
If someone with Rhinoscript skills can figure this out I would really appreciate it.
I'm doing a 2D drafting job (no 3D, just top view with connected polylines), I need to find the 'area' calculation and place that calcualtion(text) into the center of each shape. Usually there are between 7-15 closed shapes that I need to find the area have the area text placed onto. Think 'Tetris' and placing the area amount into each rectangular shape.
Right now I select the polyline shape, click 'area', copy the calcualtion from the command box, click 'text', copy the paste the area into it and move the text into the middle of the polyline shape.
I need to figure out how to automate this. Basically click on the shape, run the script and have it place the area calculation in the middle of the shape. Actually being able to do all the shapes at the same time would be even better, but I don't want to get greedy
Sounds simple but I don't know Rhinoscript at all. Any help would be appreciated!
|
|
|
|
|
|
|
|
Re:Area calculation (text) placed into shape
|
|
Hi Swanny
You can copy the following script to a button in your workspace ( for example the dimensions button has space for a right click instruction) To do this hover over the button and press the shift key, the button editing window will open. Then paste the following script in the command space be sure to include the RunScript line up to the last parenthese.
Let us know if it works for you
Phil
!-_RunScript
(
Option Explicit
'Script written by Phil Shapiro
'Script copyrighted by Cadlantique
'Script version Friday, 06 August 2010 07:11:22
Call Main()
Sub Main()
Dim arrCLosedCurveObjects, CurveObject, arrCentroidPoint, arrAreaValue, dblHeight
arrClosedCurveObjects = Rhino.GetObjects("Select curve objects",4)
dblHeight = Rhino.GetReal("Text height in Document units")
For Each CurveObject In arrClosedCurveObjects
If Rhino.IsCurveClosed(CurveObject) Then
arrCentroidPoint = Rhino.CurveAreaCentroid ( CurveObject)
arrAreaValue = Rhino.CurveArea ( CurveObject)
Call Rhino.AddText (CStr(Round(arrAreaValue(0), 3)), arrCentroidPoint(0) , dblHeight)
Else
Call Rhino.SelectObject(CurveObject)
End If
Next
End Sub
)
|
|
|
|
|
|
|
|
Re: Area calculation (text) placed into shape
|
|
If you need text added like units or something like area = xxx let us know.
Have a nice day
Phil
|
|
|
|
|
|
|
|
Re: Area calculation (text) placed into shape
|
|
Hi Phil,
Thank you so much for this script! This has really has helped me with my job ( I make roof diagrams).
Can I bother you with one more thing? Is there a way to dimension a single polyline and multiply that dimension by 1.2 , then apply the new number (text) in place?
What I normally have to do using Rhino is use the dimension tool to put a dimension on an edge/side (polyline) of the roof then get the calulator out and multiply that dimension value by 1.2 to get the true length. Then I change the number in the dimension to the new number I got by multiplying.
It would be incredibly helpful if the dimension tool does the math automatically and multiplys whatever the dim of the line is by 1.2 and apply's it to the text.
1.2 represent the pitch/slope of the roof. I would change the 1.2 to other values depending on the pitch on the roof where I'm measuring.
Any help with this would extremely appreciated.
Thanks again.
|
|
|
|
Last Edit: 2010/08/08 03:23 By swanny.
|
|
|
|
Re: Area calculation (text) placed into shape
|
|
Hi Swanny
I'm off on vacation so I read you question a bit late, I have something that should work however my pc is set to take commas as decimal separators and therefore it is not accepting the periods, so I cant really test it, I'll get back to you very shortly.
Phil
|
|
|
|
|
|
|
|
Re: Area calculation (text) placed into shape
|
|
Here Swanny
Try the following script again enclosed with the RunScript and parentheses business :
Option Explicit
'Script written by Phil Shapiro
'Script copyrighted by CadLantique
'Script version mardi 10 août 2010 17:28:09
Call Main()
Sub Main()
Dim strObject, strUserText, strDimensionText, dblNewDim
strObject = Rhino.GetObject("Select a dimension")
If Rhino.IsDimension(strObject) Then
strDimensionText = Rhino.DimensionText(strObject)
dblNewDim = (CDbl(strDimensionText)*1.2)
Rhino.DimensionUserText strObject, CStr(dblNewDIm)
End If
End Sub
|
|
|
|
|
|
|
|
Re: Area calculation (text) placed into shape
|
|
Try this one if you have other factors than 1.2, best regards Phil
Option Explicit
'Script written by Phil Shapiro
'Script copyrighted by CadLantique
'Script version mardi 10 août 2010 17:28:09
Call Main()
Sub Main()
Dim strObject, strUserText, strDimensionText, dblNewDim
Dim dblFactor
dblFactor = Rhino.GetReal("Enter Factor",1.2)
strObject = Rhino.GetObject("Select a dimension")
If Rhino.IsDimension(strObject) Then
strDimensionText = Rhino.DimensionText(strObject)
dblNewDim = (CDbl(strDimensionText)*dblFactor)
Rhino.DimensionUserText strObject, CStr(dblNewDIm)
End If
End Sub
|
|
|
|
|
|
|
|
Re: Area calculation (text) placed into shape
|
|
Phil,
I haven't tried the second script yet (I will today) but the first one works awesome, thanks! What I had originally was looking for was something that works like the dimension tool and then multiplys what you dimension out by 1.2. But this script actually works better in some ways. I use the 'auto dimension' script to dimension out the entire roof and then use your script to multiply the dimension on the peaks and valleys of the roof of the house. This will help out greatly with about 200 home I need to dimension out. I'm a script junkie now! How do you suggest learning Rhinoscript for someone who has zero programming backround?
BTW, no rush with a reply, please enjoy your vacation.
Thanks Again,
Swanny
|
|
|
|
|
|