Page 1 of 1

DimensionElementDelete deleting alternate elements

Posted: Wed Nov 08, 2017 7:17 pm
by Paul-TM1
Hi All,
I have come across a strange issue. I am trying to delete an element 'element1' and it's children in a dimension and I have looped them. When I write to a file without 'DimensionElementDelete', all the elements are written to file. But when I use the 'DimensionElementDelete', only alternate elements are deleted and only those deleted are written in the file. We use 10.2.2 FP7. Has anyone seen this before? any help is appreciated.

Thanks,
Paul.

Code: Select all

pDim = 'DimensionNm' ;
x =1 ;

WHILE(x <= DimSiz( pDim ) ) ;
  element = DimNM( pDim ,x) ;
  if ( SUBST(element , 1, 5) @=  element1 );
	asciiOutPut( degugFile , pDim, 'pDimensionSize ', numberToString ( x ),  element ) ;
	
	DimensionElementDelete(pDim, element );
	
	#After adding the line below, deleted all the elements vs alternate elements are deleted
	x = x - 1;
	# the above line would make the session hung if 'DimensionElementDelete' is not commented.
	
	asciiOutPut( degugFile , pDim, 'deleted Element', element ) ;
  endif;

  x = x + 1;
END;

Re: DimensionElementDelete deleting alternate elements

Posted: Wed Nov 08, 2017 7:27 pm
by tomok
In your loop you need to start at the last record and work forward because deleting the element is going to change the index value of all your elements past the one being deleted.

Re: DimensionElementDelete deleting alternate elements

Posted: Thu Nov 09, 2017 8:30 am
by AmbPin
Either that or only increment your loop index if you do not delete an element.

Re: DimensionElementDelete deleting alternate elements

Posted: Sat Nov 11, 2017 1:08 pm
by Moh
paul pls give the final code you used,it will help me

Re: DimensionElementDelete deleting alternate elements

Posted: Sat Nov 11, 2017 5:26 pm
by Wim Gielis

Code: Select all

pDim = 'DimensionNm' ;
x = DimSiz( pDim );
WHILE(x > 0 ) ;
  element = DimNM( pDim ,x) ;
  if ( SUBST(element, 1, 5) @= element1 );
	DimensionElementDelete(pDim, element );
  EndIf;
  x = x - 1;
END;

Re: DimensionElementDelete deleting alternate elements

Posted: Sun Nov 12, 2017 10:17 am
by lotsaram
Moh wrote: Sat Nov 11, 2017 1:08 pm paul pls give the final code you used,it will help me
There is actually a free utility available called TI Helper which can inject TI code snippets into the architect/perspectives process editor. Reverse dimension while loop is one of the included snippets.

Re: DimensionElementDelete deleting alternate elements

Posted: Mon Nov 13, 2017 4:49 pm
by Paul-TM1
Thanks Tomok. It worked.
Sorry I had not posted the code in time, but thanks Wim for posting the code.

Good to know there is a utility that helps generate code. I will be trying it now.

Thanks everyone for helping.
Paul.