how to sort extracted points in a structure made from cells
3 views (last 30 days)
Show older comments
What I did
hi, I have reported here a script capable of loading a g code file of text, containing the coordinates of the X Y Z E positions of the extruder of a 3d printer. In this file the various layers to be deposited are indicated with the words; LAYER :, followed by the number of the layer considered. the script then counts the various layers and obtains the various positions X Y Z E using the GETPOSITION function for the command lines (contained in the g code) under the captions; MESH: e; TYPE.
clear all
clc
[FileName,PathName,FilterIndex] = uigetfile({'*.gcode';'*.txt'},'Select Gcode to modify');
filename=strcat(PathName,FileName);
comando=strcat('fidR=fopen(''',filename,'''',');');
eval(comando);
%
% C=strsplit(FileName,'.');
% filename=strcat(PathName,C{1},'-modified.',C{2});
% comando3=strcat('fidW=fopen(''',filename,'''',',''','wt',''');');
%
% eval(comando3)
command=fgets(fidR);
command=strtrim(command);
PREV_POS=[0,0,0,0];
LayerCount=0; %contatore dei Layer
Part_Name=[];
Line_Type=[];
while ischar(command)
display(command);
[NEW_POS]=GETPOSITION(PREV_POS,command);
% display(PREV_POS);
% display(NEW_POS);
if contains(command,';LAYER:')
LayerCount=LayerCount+1;
disp('inizio un nuovo layer!')
end
if contains(command,';MESH:')
Part_Name=split(command,":");
Part_Name=Part_Name{2,1};
Part_Name=split(Part_Name,".");
Part_Name=Part_Name{1,1};
if contains(Part_Name,'NONMESH')
Part_Name=[];
Line_Type=[];
end
if not(isempty(Part_Name)) %se Part_Name è non vuoto, devo creare la variabile nominata solo se non è già stata creata
str=strcat('ExCheck=exist(''',Part_Name,''');');
eval(str);
if ExCheck~=1
str=strcat(Part_Name,'=[];');
eval(str);
disp('NEW VARIABLE CREATED');
end
pause
end
end
if contains(command,';TYPE:')
if contains(command,'WALL-INNER')
Line_Type='WALL-INNER';
end
if contains(command,'WALL-OUTER')
Line_Type='WALL-OUTER';
end
if contains(command,'SKIN')
Line_Type='INFILL';
end
end
disp('Layer number')
disp(LayerCount);
disp('Previous Position')
disp(PREV_POS);
disp('Part being fabricated')
disp(Part_Name)
disp('Line Type')
disp(Line_Type);
disp('Target position')
disp(NEW_POS);
clc
PREV_POS=NEW_POS;
command=fgets(fidR);
command=strtrim(command);
end
What I have to do
what I have to do is sort the points extracted from the G-Code in a structure composed of cells. The transition from one layer to the next is indicated with the string; LAYER: followed by the layer number starting from 0
0 Comments
Answers (0)
See Also
Categories
Find more on Class Introspection and Metadata in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!