CST Macros Code to MATLAB Code
    37 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
Hlw I am wring a code in matlab where I am interfacing CST using MATLAB code.For this I have to write individual function in MATLAB from CST VBA Macros code.                                                                                                                                                                                                                          
This  is a code for extrude in CST
Sub Main ()
'## Merged Block - define extrude: component1:solid1
StartVersionStringOverrideMode "2022.3|31.0.1|20220204" 
With Extrude 
     .Reset 
     .Name "solid1" 
     .Component "component1" 
     .Material "PEC" 
     .Mode "Pointlist" 
     .Height "1" 
     .Twist "0.0" 
     .Taper "0.0" 
     .Origin "0.0", "0.0", "2" 
     .Uvector "1.0", "0.0", "0.0" 
     .Vvector "0.0", "1.0", "0.0" 
     .Point "6", "1" 
     .LineTo "5", "1" 
     .LineTo "5", "2" 
     .Create 
End With
StopVersionStringOverrideMode 
End Sub   .From this I have written the following MATLAB Code for extrude function   
function Cstextrude(mws, Name, component, material, Mode, Height, Twist, Taper, Origin, Uvector, Vvector, Points)
invoke(extrude, 'Reset');
invoke(extrude, 'Name', Name);
invoke(extrude, 'Component', component);
invoke(extrude, 'Material', material);
invoke(extrude, 'Mode', Mode);
invoke(extrude, 'Height', Height);
invoke(extrude, 'Twist', Twist);
invoke(extrude, 'Taper', Taper);
invoke(extrude,'Origin', num2str(Origin(1)), num2str(Origin(2)), num2str(Origin(3)));
invoke(extrude,'Uvector', num2str(Uvector(1)), num2str(Uvector(2)), num2str(Uvector(3)));
invoke(extrude,'Vvector', num2str(Vvector(1)), num2str(Vvector(2)), num2str(Vvector(3)));
for i = 1:size(Points, 1)
        point = Points(i, :);
        X_point = point{1};
        Y_point = point{2};
        invoke(extrude, 'LineTo', X_point, Y_point);
    end
invoke(extrude, 'Create');
release(extrude);
end
But I am not getting exact shape from this code and I think  for i = 1:size(Points, 1)
        point = Points(i, :);
        X_point = point{1};
        Y_point = point{2};
        invoke(extrude, 'LineTo', X_point, Y_point);
    end this part might be not showing what  
      Point "6", "1" 
     .LineTo "5", "1" 
     .LineTo "5", "2"  this part is doing in vba macros in cst.   
     Can anyone please tell me   
       for i = 1:size(Points, 1)
        point = Points(i, :);
        X_point = point{1};
        Y_point = point{2};
        invoke(extrude, 'LineTo', X_point, Y_point); is this part is correct?
0 comentarios
Respuestas (1)
  Narvik
      
 el 30 de Oct. de 2024
        Hi Mashrur Zawad,
As per my understanding, you are trying to write a MATLAB function from CST VBA Macro code.
In your CST VBA macro code, you define a point and then draw lines to create the shape:
.Point "6", "1" 
.LineTo "5", "1" 
.LineTo "5", "2" 
In your MATLAB function, follow the same process i.e., set the initial point using the "Point" method and draw lines using the "LineTo" method from that initial point to other points.
Refer to the following updated MATLAB function:
function Cstextrude(mws, Name, component, material, Mode, Height, Twist, Taper, Origin, Uvector, Vvector, Points)
    extrude = invoke(mws, 'Extrude');
    invoke(extrude, 'Reset');
    invoke(extrude, 'Name', Name);
    invoke(extrude, 'Component', component);
    invoke(extrude, 'Material', material);
    invoke(extrude, 'Mode', Mode);
    invoke(extrude, 'Height', Height);
    invoke(extrude, 'Twist', Twist);
    invoke(extrude, 'Taper', Taper);
    invoke(extrude, 'Origin', num2str(Origin(1)), num2str(Origin(2)), num2str(Origin(3)));
    invoke(extrude, 'Uvector', num2str(Uvector(1)), num2str(Uvector(2)), num2str(Uvector(3)));
    invoke(extrude, 'Vvector', num2str(Vvector(1)), num2str(Vvector(2)), num2str(Vvector(3)));
    % Set the initial point
    initialPoint = Points(1, :);
    invoke(extrude, 'Point', num2str(initialPoint(1)), num2str(initialPoint(2)));
    % Use LineTo for remaining points
    for i = 2:size(Points, 1)
        point = Points(i, :);
        X_point = num2str(point(1));
        Y_point = num2str(point(2));
        invoke(extrude, 'LineTo', X_point, Y_point);
    end
    invoke(extrude, 'Create');
    release(extrude);
end
Hope this helps!
1 comentario
Ver también
Categorías
				Más información sobre Read, Write, and Modify Image en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


