cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

get left and bottom most edges from drawing view

Aravind98
11-Garnet

get left and bottom most edges from drawing view

Hi all.

 

In Creo toolkit how to take left and bottom most edges from the drawing view(not a model view)?

if anyone knows pls help me

 

Thanks

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

1. Visit all views using ProDrawingViewVisit

2. Use ProDrawingViewSheetGet to determine the sheet number of the visited view

3. Compare positions using ProDrawingViewOutlineGet for the same sheet number

Below is sample code to get the bottom left view for recent sheets.

static int curSheet = -1;
ProError userViewVisit(ProDrawing drw,ProView view,ProError status,ProAppData data)
{
	int viewSheet = -1;
	status = ProDrawingViewSheetGet(drw,view,&viewSheet);
	if(curSheet == viewSheet)
	{
		ProName viewName;
		status = ProViewNameGet(*(ProView*)data,viewName);	
		if(status!=PRO_TK_NO_ERROR)	*(ProView*)data = view;
		else
		{
			Pro3dPnt VeiwSize_1[2],VeiwSize_2[2];
			status = ProDrawingViewOutlineGet(drw,view,VeiwSize_1);
			status = ProDrawingViewOutlineGet(drw,*(ProView*)data,VeiwSize_2);
			if(VeiwSize_1[0][0] < VeiwSize_2[0][0] || VeiwSize_1[0][1] < VeiwSize_2[0][1])
			{
				*(ProView*)data = view;
			}
		}		
	}
	return PRO_TK_NO_ERROR;
}
ProError userTest()
{
	ProMdl drw;
	ProError status = ProMdlCurrentGet(&drw);
	if(status != PRO_TK_NO_ERROR)	return status;
	ProMdlType type;
	status = ProMdlTypeGet(drw,&type);
	if(type != PRO_MDL_DRAWING)	return PRO_TK_BAD_CONTEXT;
	status = ProDrawingCurrentSheetGet((ProDrawing)drw,&curSheet);
	ProView leftBottomView = NULL;
	status = ProDrawingViewVisit((ProDrawing)drw,(ProViewVisitAction)userViewVisit , NULL,&leftBottomView);
	if(leftBottomView != NULL)
	{
		ProName viewName;
		status = ProViewNameGet(leftBottomView,viewName);
		ProMessageDisplay(MSGFIL,"USER %0ls",viewName);
	}
	return PRO_TK_NO_ERROR;
}

View solution in original post

7 REPLIES 7

Have a look at ProDrawingViewOutlineGet function.

yes but with this i couldn't find the left most drawing view

RPN
17-Peridot
17-Peridot
(To:Aravind98)

What about to visit each view on a sheet and compare 🤪

1. Visit all views using ProDrawingViewVisit

2. Use ProDrawingViewSheetGet to determine the sheet number of the visited view

3. Compare positions using ProDrawingViewOutlineGet for the same sheet number

Below is sample code to get the bottom left view for recent sheets.

static int curSheet = -1;
ProError userViewVisit(ProDrawing drw,ProView view,ProError status,ProAppData data)
{
	int viewSheet = -1;
	status = ProDrawingViewSheetGet(drw,view,&viewSheet);
	if(curSheet == viewSheet)
	{
		ProName viewName;
		status = ProViewNameGet(*(ProView*)data,viewName);	
		if(status!=PRO_TK_NO_ERROR)	*(ProView*)data = view;
		else
		{
			Pro3dPnt VeiwSize_1[2],VeiwSize_2[2];
			status = ProDrawingViewOutlineGet(drw,view,VeiwSize_1);
			status = ProDrawingViewOutlineGet(drw,*(ProView*)data,VeiwSize_2);
			if(VeiwSize_1[0][0] < VeiwSize_2[0][0] || VeiwSize_1[0][1] < VeiwSize_2[0][1])
			{
				*(ProView*)data = view;
			}
		}		
	}
	return PRO_TK_NO_ERROR;
}
ProError userTest()
{
	ProMdl drw;
	ProError status = ProMdlCurrentGet(&drw);
	if(status != PRO_TK_NO_ERROR)	return status;
	ProMdlType type;
	status = ProMdlTypeGet(drw,&type);
	if(type != PRO_MDL_DRAWING)	return PRO_TK_BAD_CONTEXT;
	status = ProDrawingCurrentSheetGet((ProDrawing)drw,&curSheet);
	ProView leftBottomView = NULL;
	status = ProDrawingViewVisit((ProDrawing)drw,(ProViewVisitAction)userViewVisit , NULL,&leftBottomView);
	if(leftBottomView != NULL)
	{
		ProName viewName;
		status = ProViewNameGet(leftBottomView,viewName);
		ProMessageDisplay(MSGFIL,"USER %0ls",viewName);
	}
	return PRO_TK_NO_ERROR;
}
RPN
17-Peridot
17-Peridot
(To:CHASEONHO)

What about this 😂

 

set xvalList [list]
foreach view [ps_view list] {
   ps_view outline $view outLineObj
   lappend xvalList [list $view [outLineObj cget -x1] ]
   lappend xvalList [list $view [outLineObj cget -x2] ]
}
set minItem  [lindex [lsort -incr -index 1 $xvalList ] 0]
lassign  $minItem ViewName xVal
Debug "The View $ViewName is topleft with x $xVal"
RPN
17-Peridot
17-Peridot
(To:CHASEONHO)

I was probably to fast (tested for one sheet only, and first think, than …) with my answer (I checked only x), and Chesonho code may not return the correct view, but for sure he spend more time on it 👍

 

Let’s assume 3 rectangle where the outline call gives you at index 0 bottom left for one view (Note, this is a guess, you may end up to compare this by yourself)

 

Her a sample table

 

X

Y

3

5

4

3

2

4

 

If I understand your request correctly, the pair 4/3 must be your view of interest. Because it is the lowest with the smallest x value.

 

Chesonho expression:

 

if(VeiwSize_1[0][0] < VeiwSize_2[0][0] || VeiwSize_1[0][1] < VeiwSize_2[0][1])

 

In pseudo code, with n as your loop index, and res for your current result.

 

if(xn < xres ||  yn < yres)

 

With this expression you will find the pair 2/4, but this view is more up.

 

Now my second try 😉

 

First you have to exclude the simple case (Done in the c-code),

  1. You must check to have a view at all
  2. If you have only one view then you have it right now

 

You should end up to find a view with the smallest y value and the smallest x value.

 

Now that you have more than one, you init xres and yres from the first view, and you need to compare always a pair of coordinates from the same view.

 

First you compare if the next view has has a smaller y value, if true, the view is lower and you have to take it. If this is false, you need to compare the x value. If this is more left or equal, it must also more down. Only in this case, this is your new result view. If not, you should ignore it.

 

This code must be repeated for 1 to N-1 😉

 

This may end up to find a view which is more on the right side, but you want to know bottom left.

 

More Pseudo Code:

 

# check if more down

If (yn < yres)

  # this view is lower

    Yres = yn

    Xres = xn

else if xn <= xres

# this one is more left but only valid if lower

  If (yn < yres)

     Yres = yn

     Xres = xn

Endif

Endif

 

Note: You can use the Visit function, but there is also a function where you get the views in one array. And here the size gives you immediate a result for zero and one.

 

It is more complicated, not a simple sort 😩 But maybe I’m still wrong 😑 

Cheers

RPN
17-Peridot
17-Peridot
(To:RPN)

For me it does look good, test with a couple of views  🙂

 

set curSheet	[ps_sheet current ]
set views		[ps_view list $curSheet]
set numViews	[llength $views]

if {$numViews == 0} {
	ps_mess "No views found"
	return
} elseif  {$numViews == 1} {
	ps_view outline $views outLineObj
	lassign [outLineObj 2d ] x1 y1
	ps_mess "One View $views is topleft with x $x1 y $y1"
	return
}

set resView [lindex $views 0]
ps_view outline  $resView outLineObj
lassign [outLineObj 2d ] xres yres

foreach view [lrange $views 1 end] {
	ps_view outline $view outLineObj
	lassign [outLineObj 2d_values ] xn yn
	if { $yn < $yres } {
 # this view is lower
		set resView $view
		set xres $xn
		set yres $yn
	} elseif { $xn <= $xres} {
# this one is more left but only valid if lower
		if { $yn < $yres } {
			set resView $view
			set xres $xn
			set yres $yn
		}
	}
}
ps_mess "The View $resView is bottom left with with x $xres y $yres"

 

botleft.png

Top Tags