This is an old revision of the document!
In order to generate nice visualizations and animations, CAD geometry can be added to Spavisual. At this page, an example is provided how CAD geometry can be added to the visualization by exploiting the USERPLOT function of spavisual.
First of all, the CAD geometry has to be saved in an .STL file. When saving the .STL file, it is important to save as ASCII with units in meters. In Solidworks, these settings can be set via 'save as ⇒ select .stl ⇒ options'. Next, the opt.customvis
field is going to be used to add extra visualization commands to the .dat file (check the spavisual manual for all supported commands). In example, the USERPLOT function can be added with:
opt.customvis = {'USERPLOT ADDCAD'}
where “ADDCAD” is the name of a matlab function (saved in CAPITALS!) which is called in the visualization procedure. Bellow, an example is provided for loading
function [ handles ] = ADDCAD(axis,handles) % Mark Naves % m.naves@utwente.nl % 4-10-2017 %Just an example how to add cad data to spavisual % %In visualization part of dat-file: USERPLOT ADDCAD %Function requires stl2fv.m % %Check correct stl settings before saving. in save as => select .stl => %options => output as ASCII, unit as meters %% x_node = 5; %position node to follow () r_node = 6; %rotation node follow Color = [162 195 214]./255; %remember cad data to improve speed persistent V H %time step t = axis.anim.CurrentTimeStep; %time step for motion v = axis.anim.CurrentVibrStep; %time step for vibrations %spacar data lnp = axis.spacar.lnp; if strcmp(axis.anim.CurrentField,'CurrentTimeStep') || strcmp(axis.anim.CurrentField,'CurrentLoadStep') x = axis.spacar.x(:,t); else x = axis.anim.Modes.X(:,v); end %Position of the node x_pos = x(lnp(x_node,1:3)); q_pos = x(lnp(r_node,1:4)); R = quat2rotm(q_pos'); %plot/update cad data if strcmp(axis.handles.figure.Visible, 'off') [F,V] = stl2fv('wrench'); H =patch('Faces', F, 'Vertices', V*R'+repmat((x_pos)',size(V,1),1),'FaceColor' ,Color,'EdgeAlpha',0); H.FaceVertexCData = repmat(Color,size(V,1),1); else H.Vertices = V*R'+repmat((x_pos)',size(V,1),1); end end