Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to check for duplicate dimensions

Status
Not open for further replies.

gauravd1991

Mechanical
Jul 28, 2013
2
IN
Hi
I am new to this forum, and some help on a problem would be great.
I was thinking of creating a macro to check for duplicate dimensions across different views in a drawing file.
I have never used VB scripting before. But, I have written the equivalent code in C++ (which i am familiar with)
Now, I want to read dimensions from a drawing file, and put it in a file from where i can use the following algorithm.
I think it is possible, i just don't know how. The C++ algorithm is below:

#include<iostream>
#include<conio.h>
#include<stdio.h>
void clear_screen()
{
int i;
for(i=0;i<100;i++)
std::cout<<"\n";
}

using namespace std;
int main()
{
clear_screen();
int no_views, dim_max;
float dims[10][100];
int counter,ctr, ctr1;
std::cout<<"Enter total no. of views in drawing sheets\n";
std::cin>>no_views;

std::cout<<" out of all the views, please enter the number of dimensions in the view with the most dimensions\n";
std::cin>>dim_max;
std::cout<<"start entering dims. view wise\n";
for(ctr=0;ctr<no_views;ctr++)
{ ctr1=ctr+1;
std::cout<<"enter dimesnsion for view: "<<ctr1<<"\n";
for(counter=0;counter<dim_max;counter++)
std::cin>>dims[ctr][counter];
}

//output check
std::cout<<dims[0][3]<<"\n\n";
std::cout<<"entered dims as follows\n";
for(ctr=0;ctr<no_views;ctr++)
{
for(counter=0;counter<dim_max;counter++)
std::cout<<dims[ctr][counter]<<"\t";
std::cout<<"\n";
}

if(no_views<=1)
std::cout<<"No comparison needed\n";

else
{

/* Somehow, we have to get inputs of the dimensions from all views in VBA and store in array dims */

int i,j,k,dj;
j=no_views-1; dj;
int dim;

do
{

dj=0;

do
{


/*cout<<"view no "<<(dj+1)<<"\nenter total no of dimensions in current view:\n";
cin>>dim_max;
*/
for(k=j-1;k>=0;k--)
{

for(dim=0;dim<=dim_max;dim++)
{
if( (dims[j][dj]==dims[k][dim])&&(dims[j][dj]!=0))
std::cout<<"following dimension repeated, check!: "<< dims[k][dim]<<" view number: "<<(j+1)<<"\n";
else
std::cout<<"not repeated yet\n";
} //end of inner for loop

} //end of outer for loop

dj++;


} while (dj<dim_max);

j--;

}while(j>0);

}


getch();
return 0;
}

Any ideas?
 
Replies continue below

Recommended for you

Hi,

Well, in my opinion this is a little bit tricky...speaking from engineering point of view this is possible...you can have same dimension in different views for different objects.

Otherwise, if you are interested just to find dimensions values...this is a quick modification of another macro which I'm sure is existing here in the forum but I wasn't able to find it.


Code:
' ======================================================
' Purpose: Macro will write all dimensions in an active CATIA drawing to a text file
' Usage:   1 - A CATDrawing must be active and  dimensions should also exist inside
'          2 - Run macro
 '         3  - Use a rectangle selection to select all your dimensions
' Author: ferdo (Disclaimer: You use this code at your own risk) 
' ======================================================
Language="VBSCRIPT"

Sub CATMain()

Dim InputObjectType(0) As String
set document = CATIA.ActiveDocument

If TypeName(document)="DrawingDocument" then
		set oSelection = document.Selection
		InputObjectType(0)="DrawingDimension"
		oSelection.SelectElement3 InputObjectType,"Select points", _ 
                                 true,CATMultiSelTriggWhenSelPerf,false
		WriteTxTFile(oSelection)
		oSelection.clear
Else
End If
End Sub

Sub WriteTxTFile(oSelection)

Dim sPath As String
Dim sTime As String
Dim sName As String
Dim sFile As String

documentname = CATIA.ActiveDocument.Name
position = InStr(documentname,".CATDrawing")
position = position -1
documentname = Left(documentname,position)

sPath = CATIA.Application.SystemService.Environ("CATReport")            
sName = "\DrawingDimension_" & documentname & ".TXT"       
sFile = sPath & sName

Set oFileOut = CATIA.FileSystem.CreateFile(sFile,TRUE)
Dim oStream As TextStream
Set oStream = oFileOut.OpenAsTextStream("ForWriting")

For i=1 to oSelection.count
	Set Dimension = oSelection.Item(i).Value
	oStream.Write Dimension.GetValue.Value & vbCrLf
Next

oStream.close
MsgBox "Check the file : " & sFile, vbInformation                       ' information about job done

End Sub

Regards
Fernando

 
Hey Fernando

Yeah, I knew that there are cases where the same value of dimension is used for different features on a drawing. But, I still want to do this, because sometimes when there are a lot of dimensions, just a highlight of the dimension repeated can guide the draftsman. We can then use our logic to check if it is really duplicate or not. we don't have to pore through everything.
Anyway, your macro for getting dimensions in a text file was flawless!! Thanks for that! I can save it as an excel file also, which is interesting. If I can somehow segregate dimensions from different views into an excel sheet, i can maybe insert my algorithm there. Is that possible with a catia macro? asking user to just pick rectangles enclosing single views at a time, and saving those dimensions in the same excel sheet?

Thanks for all the help!

Gaurav
 
That was just an example...

Of course you can do much more in a CATIA macro...you can go thru each sheet (if you have more) and thru each view, get all dimensions...you don't need to select something (like in this macro), just use search criteria in a loop for each view and each sheet, save all in Excel or whatever.

You can search forum for more examples.

Regards
Fernando

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top