Skip to content

Commit

Permalink
Adding rhino3dm ReadTextEntity sample
Browse files Browse the repository at this point in the history
  • Loading branch information
fraguada committed Mar 15, 2024
1 parent 8f728b0 commit ac85304
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 0 deletions.
29 changes: 29 additions & 0 deletions rhino3dm/cs/SampleCSReadTextEntities/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Rhino.FileIO;

Console.WriteLine("---Sample: Read Text Entities from file---");

var path = Directory.GetCurrentDirectory();

Console.WriteLine("Current Directory: {0}",path);

File3dm file3dm = new File3dm();

//the path will be different whether you are using dotnet run or debugging
if(path.Contains("net7.0")){
file3dm = File3dm.Read("../../../../../models/textEntities_r8.3dm");
} else{
file3dm = File3dm.Read("../../models/textEntities_r8.3dm");
}

Console.WriteLine("Number of objects in file {0}", file3dm.Objects.Count);

foreach( var ro in file3dm.Objects )
{
var te = ro.Geometry as Rhino.Geometry.TextEntity;
if( te != null) {
Console.WriteLine("-----------");
Console.WriteLine("Plain text: {0}", te.PlainText);
Console.WriteLine("Rich text: {0}", te.RichText);
Console.WriteLine("Plain text with fields: {0}", te.PlainTextWithFields);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Rhino3dm" Version="8.6.0-beta" />
</ItemGroup>

</Project>
22 changes: 22 additions & 0 deletions rhino3dm/cs/SampleCSReadTextEntities/SampleCSTextEntitiesRead.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleCSTextEntitiesRead", "SampleCSTextEntitiesRead.csproj", "{94766DA2-2B87-413E-95E3-AFAF81E4542A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{94766DA2-2B87-413E-95E3-AFAF81E4542A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94766DA2-2B87-413E-95E3-AFAF81E4542A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94766DA2-2B87-413E-95E3-AFAF81E4542A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94766DA2-2B87-413E-95E3-AFAF81E4542A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
23 changes: 23 additions & 0 deletions rhino3dm/js/node/SampleReadTextEntities/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as fs from 'fs'
import rhino3dm from 'rhino3dm'

const rhino = await rhino3dm()
console.log('Loaded rhino3dm.')

// read model
const model = '../../../models/textEntities_r8.3dm'

const buffer = fs.readFileSync(model)
const arr = new Uint8Array(buffer)
const doc = rhino.File3dm.fromByteArray(arr)
const objects = doc.objects()

for ( let i = 0; i < objects.count; i ++ ) {
const ro = objects.get(i)
const geometry = ro.geometry()
console.log('-------------------')
console.log(geometry.plainText)
console.log(geometry.plainTextWithFields)
console.log(geometry.richText)

}
30 changes: 30 additions & 0 deletions rhino3dm/js/node/SampleReadTextEntities/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions rhino3dm/js/node/SampleReadTextEntities/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "sampletextentities",
"version": "0.0.1",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"rhino3dm": "^8.6.0-dev"
}
}
10 changes: 10 additions & 0 deletions rhino3dm/py/SampleReadTextEntities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# requires rhino3dm.py ^8.6.0b0
import rhino3dm
model = rhino3dm.File3dm.Read('../models/textEntities_r8.3dm')
objects = model.Objects
for obj in objects:
geo = obj.Geometry
print(geo.ObjectType)
print(geo.PlainText)
print(geo.RichText)
print(geo.PlainTextWithFields)

0 comments on commit ac85304

Please sign in to comment.