Hello @enric,
I read in your post about the ne features of va2.4 that there now is a scripting API.
Can you link me to some samples of using it? I can’t seem to find any.
Many thanks,
Lando
Hello @enric,
I read in your post about the ne features of va2.4 that there now is a scripting API.
Can you link me to some samples of using it? I can’t seem to find any.
Many thanks,
Lando
Hi @lando.schumpich,
We’re currently working on the documentation and samples for the new VisualARQ Script API, but nothing is public yet.
VisualARQ Script API is currently only accessible from RhinoCommon (C#, VB.NET, Python), but new version will allow to access this API from C++ and RhinoScript.
VisualARQ Script API is still in WIP, and not all features are still exposed in the API. VisualARQ 2.4 has methods to work with:
VisualARQ 2.5 will include more objects in the API. If you need any method in particular, just ask for it and I’ll try to include it in the next release. I’m currently working in all Beam/Column/Door/Window methods.
To use the API, just reference the VisualARQ.Script.dll
assembly that is installed with VisualARQ. You’ll find it next to Rhino.exe
, usually in C:\Program Files\Rhino 6\System
. This API has been created to work with document resident objects (create, edit, modify and delete) using their object ID. All methods are members of an static class VisualARQ.Script
. In order to use the API, you don’t need to do anything in particular, just call any method. If VisualARQ is not yet loaded, the assembly will take care of any initialization needed on the first VisualARQ Script call.
Here is a sample code using the API:
using System;
using System.Collections.Generic;
using Rhino;
using Rhino.Commands;
using Rhino.Geometry;
using Rhino.Input;
using Rhino.Input.Custom;
using va = VisualARQ.Script;
namespace VisualARQ
{
public class VaScriptSampleCommand : Command
{
public VaScriptSampleCommand()
{
// Rhino only creates one instance of each command class defined in a
// plug-in, so it is safe to store a refence in a static property.
Instance = this;
}
///<summary>The only instance of this command.</summary>
public static VaScriptSampleCommand Instance
{
get; private set;
}
///<returns>The command name as it appears on the Rhino command line.</returns>
public override string EnglishName
{
get { return "ScriptSampleCommand"; }
}
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
// Get units scale factor from meters to document units
double unitScale = RhinoMath.UnitScale(UnitSystem.Meters, doc.ModelUnitSystem);
// Create a block with a 3D sphere as mnodel representation
var sphere = Brep.CreateFromSphere(new Sphere(Point3d.Origin, 1.0 * unitScale));
doc.InstanceDefinitions.Add("Sphere", string.Empty, Point3d.Origin, new[] { sphere });
// Create a block with a 2D rectangle as plan representation
var retangle = new ArcCurve(new Circle(Point3d.Origin, 1.0 * unitScale));
var idefIndex = doc.InstanceDefinitions.Add("Circle", string.Empty, Point3d.Origin, new[] { retangle });
// Create a VisualARQ Generic Element Style
var styleId = va.AddGenericElementStyle("Sphere", new List<string>() { "Sphere" }, new List<string>() { "Circle" });
// Insert VisualARQ Generic Element
var elementId = va.AddGenericElement(styleId, new Point3d(1.0, 1.0, 1.0), 2.0);
// Change Element position
Point3d pos = va.GetGenericElementPosition(elementId);
va.SetGenericElementPosition(elementId, pos + new Vector3d(2.0, 2.0, -2.0));
// Create a document parameter "price"
var priceId = va.AddDocumentParameter("Price", va.ParameterType.Currency, "Costs");
// Set "Price" value to element
va.SetParameterValue(priceId, elementId, 100.0);
return Result.Success;
}
}
}
Let me know if you have any doubts or issues using the API.
Regards,
Enric
Hello Enric,
I want to clean my elementstyle list using this script:
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino as R
import clr
import sys
sys.path.append(r"C:\Program Files\Rhino 6\System")
clr.AddReference ("VisualARQ.Script.dll")
import VisualARQ.Script as va
# get object guids
guids = rs.GetObjects('select objects')
# get references to object geometries
geometries = []
for guid in guids:
geometries.append(rs.coercegeometry(guid))
#GetElementName
ObjName = rs.ObjectName(guids[0])
#MakeSure That the previouseStyle is deleted
ExistedStyles = va.GetGenericElementStyleId(ObjName)
va.DeleteStyle(ExistedStyles)
M = rs.BlockNames(True)
if len(M)>1:
for i in M:
if i == ObjName:
rs.DeleteBlock(i)
But it turned out that the element style was not deleted and it is not detetable any more.
can you tell me what is wrong with my method ?
Hi @tish.ghaith,
I’m curently out of the office on vacations, so I cannot test your script, but I think I know what is going on:
VisualARQ has a current style for each element type. This style is internally stored in a template element stored inside the document, so each time you run a insert command on a document, the last settings used in the command are used.
You can change the current style using the function VA_SetCurrentGenericElementStyle
, but you need to pass a valid style id.
One more thing: you are using the element name to find the element style… is that correct?
Regards,
Enric
HI Enric,
I have just solved it by deleting the element instances before deleting the styles. The problem is that the style manager in visual arq dont replace the styles automatically. The second problem is that you cant delete a style when you have elements in the rhino documents that holds it. In rhino for example you can delete the block definition without the need to delete the instances that hold the definition.
This was the coding solution:
guids = rs.GetObjects(‘select objects’)
for i in guids:
if va.IsElement(i):
ObjName = rs.ObjectName(i)
rs.DeleteObject(i)
ExistedStyles = va.GetGenericElementStyleId(ObjName)
va.DeleteStyle(ExistedStyles)