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

How to Export all the Dimensions of the 3D CAD model or CAD assembly in to the excel

SOLVED
SM_9791973
7-Bedrock

How to Export all the Dimensions of the 3D CAD model or CAD assembly in to the excel

Hi,

Actually, I have to export all the 3D CAD model dimensions or CAD assembly dimension in to the excel so how it is possible through the programming as I have to this exercise repeatedly irrespective of the model (CAD assembly) so I thought it's better to write program for this. Does it is beneficial to control or export through VBA or what could be the easy approach to get all the dimensions...

Any approach or suggestions are welcome.

 

Thank you,

Shubham.

1 ACCEPTED SOLUTION

Accepted Solutions
RPN
13-Aquamarine
13-Aquamarine
(To:SM_9791973)

Some scripts (Tcl)

Note: the requirements are unclear 😀

This will just export any dimension id, symbol and value from the current model

 

 

 

 

 

# Just Do It for the current active model
# with hardcoded seperator ','
# out may look like this
# 0,d0,360.0
# 2,d2,32.0
# 3,d3,66.0
# 5,d5,7.5
# 6,d6,4.25
# 10,d10,60.0

proc DimShort {} {
	set out [file join [ps_pwd] Dim-[ps_model current].csv]
	set fp [open  $out w]
	foreach item [ps_dim list] {
		puts $fp [join $item ,]
	}
	close $fp
}
# Just call the procedure
DimShort

 

 

 

 

 

 

Add some header and notes.

 

 

 

 

 


# with some note and a file header
proc SimpleOut {model {sep {,}} } {
	# prepare the output filename
	# use the current working dir of Creo get by 'ps_pwd'
	# 
	# and use the model name within the file name
	# if our current folder is c:/Creo/Work and the model name is box.prt
	# out would be  c:/Creo/Work/SimpleDim-box.prt.csv
	#
	set out [file join [ps_pwd] SimpleDim-$model.csv]

	# open the file for write
	set fp [open  $out w]

	# prepare a header, if not skip the next 2  lines of code
	# could be done in onle line as well
	set COLS [list  DimID DimSymbol DimValue]
	puts $fp [join $COLS ,]

	# ps_dim list will return a list, each list item has 3 information
	# the dimension ID, the symbol name, and the value
	# e.g.
	# ps_dim list will return  {6 d6 4.25} {10 boxlen 60.0} ...

	foreach item [ps_dim list -model $model] {
		puts $fp [join $item ,]
	}

	# close the open file
	close $fp

}

 

 

 

 

 

 

You may want only dimensions for active, not suppressed features

 

 

 

 

 

#
# export only dims for active features
# Note: The the pattern dir value is not a dimension
#
# FeatID,DimID,DimSymbol,DimValue
# 39,2,d2,32.0
# 39,3,d3,66.0
# 39,5,d5,7.5

proc ActiveOut {model {sep {,}} } {

	# prepare the output filename
	# use the current working dir of Creo get by 'ps_pwd'
	# 
	# and use the model name within the file name
	# if our current folder is c:/Creo/Work and the model name is box.prt
	# out would be  c:/Creo/Work/ActiveSimpleDim-box.prt.csv
	#
	set out [file join [ps_pwd] ActiveSimpleDim-$model.csv]

	# open the file for write
	set fp [open  $out w]

	# prepare a header, if not skip the next 2  lines of code
	# could be done in onle line as well
	set COLS [list  FeatID DimID DimSymbol DimValue]
	puts $fp [join $COLS ,]

	# Get all active feature IDs, skip suppressed ...
	set ActiveFeats [ps_feat list -active true]

	# this will return a nested list
	# foreach ActiveFeats ID a list of dims or an empty list
	set dimObjLists  [ps_dim by_feat  -model $model -- $ActiveFeats] 

	# now check the list for each feat id
	foreach dimObjList $dimObjLists ActiveFeat $ActiveFeats {

		# if we have no dim for this feature continue
		if {[llength $dimObjList] == 0} continue

		# walk through the list of dimObj
		foreach dimObj $dimObjList {

			# get id, symbol and value
			set id 	[$dimObj cget -id]
			set sym [$dimObj cget -symbol]
			set val [$dimObj cget -value]

			# write to file
			puts $fp [join [list $ActiveFeat $id $sym $val] ,]


		}

	}

	close $fp

}
# Call with the current model
ActiveOut [ps_model cur]

 

 

 

 

 

 

Last example: Just export a specific dimension type including tolerance and some dimension tags

 

 

 

 

 

#
# export only a dimension value from type diameter
# add tolernce values and inspection basic info

# sample out (of course out is without the '#')
# Symbol,Value,TolL,TolH,Inspection,Basic
# d2,32.000,0.005334,0.005334,No,No
# d12,5.334,0.005334,0.005334,No,No
# d27,10.667,0.005334,0.005334,No,No

# if sep is not given use ','
proc SimpleByType {model { sep {,} } } {
	set B(0) No
	set B(1) Yes
	set dims [ps_dim list]

	set out [file join [ps_pwd] dim-info-by-type--$model.csv]

	set fp [open $out w]

	puts $fp "Symbol,Value,TolL,TolH,Inspection,Basic"

	foreach item $dims {

		# assign id sym val to a var from the list item
		foreach {id sym val} $item break

		# get the dim Object handle
		set dimObj [ps_dim from_ids $id]
		# Only export if we have a diameter dimension	
		if {[string equal [$dimObj cget -type ] DIAMETER ] } {

			# get the tolerance, a list of 2 double values
			set tol 	[$dimObj  cget -tolerance ]
			# assign lower, upper value
			set toll 	[lindex $tol 0 ]
			set tolu 	[lindex $tol 1 ]
			#export if inspection or basic
			set insp 	[$dimObj  cget -inspection ]
			set basic 	[$dimObj  cget -basic ]

			set data [join [list $sym [format %.3f $val] $toll $tolu $B($insp) $B($basic)] $sep]
			puts $fp $data
		}


	}

	# close the file
	close $fp

}

# just call the procedure with the current model
SimpleByType[ps_model cur]

 

 

 

 

 

 

Thats it, good luck with VB.

View solution in original post

9 REPLIES 9
JB_87049
15-Moonstone
(To:SM_9791973)

I've already written a toolkit application in C that is capable of doing this for my PhD study which is about the use of MBD within manufacturing.
One of the first things I found out was that a special additional license was needed in order to be able to use the APIs that you need to interrogate 3D annotations (dimensions, ...). The regular toolkit license is not enough.
I also discovered that things are not as straightforward as you might expect. When you go through the available APIs you expect to be able to scan the annotations without too many problems. This was certainly not the case. It took me quite some time to figure out how I could circumvent some shortcomings within the available APIs.

 

What you could try is the following

- select the annotations using the find button (the binoculars icon at the bottom)

- press right mouse button and display the parameters (keep in mind though this does not work for all types of dimensions but perhaps it is sufficient for you)

- export the displayed parameters to a CSV file

 

Best regards,

    John Bijnens

Thanks John for one of the approach.

But my concern was to automate or something through script or some other means, in your approach I am not able to export all the dimensions in to .csv file. 

could you pl. help by letting me know how to export the all dimensions or other better way.

 

Regards,

Shubham

JB_87049
15-Moonstone
(To:SM_9791973)

If you want to do it all within Creo itself as you mentioned in a previous reply regarding CreoSon you could try the following use the find (the binoculars icon) tool to find and select all the "annotations" and "annotation elements", press the right mouse button, select parameters and export them to a csv file you can manipulate within Excel or with your own software. You could automate the finding/selecting/exporting  by creating a mapkey for it. However, I'm not sure whether this method will allow you to really catch everything. That is something that you need to test.

 

Best regards,

    John

RPN
13-Aquamarine
13-Aquamarine
(To:SM_9791973)

You want to modify dimensions of a model from Excel?

SM_9791973
7-Bedrock
(To:RPN)

Nope I just want to export all the CAD model dimensions or CAD assembly dimensions irrespective of the model..... means one should be there means (programming or something like that which extract the data irrespective of the model if any model opened it should be capable to give all the dimensions)..

TomU
23-Emerald II
(To:SM_9791973)

Not sure if you want to do this with native Creo capability or if you're open to using 3rd party products.  We use SmartAssembly for all kinds of stuff and I have a simple program I wrote that does this exact thing.  It also seems like you should be able to do pretty easily do this with Nitro-CELL and/or CREO|SON (and the second one is completely free.)

SM_9791973
7-Bedrock
(To:TomU)

Thanks for the reply...

Is there any option with in the creo itself?

 

Regards,

Shubham

RPN
13-Aquamarine
13-Aquamarine
(To:SM_9791973)

Some scripts (Tcl)

Note: the requirements are unclear 😀

This will just export any dimension id, symbol and value from the current model

 

 

 

 

 

# Just Do It for the current active model
# with hardcoded seperator ','
# out may look like this
# 0,d0,360.0
# 2,d2,32.0
# 3,d3,66.0
# 5,d5,7.5
# 6,d6,4.25
# 10,d10,60.0

proc DimShort {} {
	set out [file join [ps_pwd] Dim-[ps_model current].csv]
	set fp [open  $out w]
	foreach item [ps_dim list] {
		puts $fp [join $item ,]
	}
	close $fp
}
# Just call the procedure
DimShort

 

 

 

 

 

 

Add some header and notes.

 

 

 

 

 


# with some note and a file header
proc SimpleOut {model {sep {,}} } {
	# prepare the output filename
	# use the current working dir of Creo get by 'ps_pwd'
	# 
	# and use the model name within the file name
	# if our current folder is c:/Creo/Work and the model name is box.prt
	# out would be  c:/Creo/Work/SimpleDim-box.prt.csv
	#
	set out [file join [ps_pwd] SimpleDim-$model.csv]

	# open the file for write
	set fp [open  $out w]

	# prepare a header, if not skip the next 2  lines of code
	# could be done in onle line as well
	set COLS [list  DimID DimSymbol DimValue]
	puts $fp [join $COLS ,]

	# ps_dim list will return a list, each list item has 3 information
	# the dimension ID, the symbol name, and the value
	# e.g.
	# ps_dim list will return  {6 d6 4.25} {10 boxlen 60.0} ...

	foreach item [ps_dim list -model $model] {
		puts $fp [join $item ,]
	}

	# close the open file
	close $fp

}

 

 

 

 

 

 

You may want only dimensions for active, not suppressed features

 

 

 

 

 

#
# export only dims for active features
# Note: The the pattern dir value is not a dimension
#
# FeatID,DimID,DimSymbol,DimValue
# 39,2,d2,32.0
# 39,3,d3,66.0
# 39,5,d5,7.5

proc ActiveOut {model {sep {,}} } {

	# prepare the output filename
	# use the current working dir of Creo get by 'ps_pwd'
	# 
	# and use the model name within the file name
	# if our current folder is c:/Creo/Work and the model name is box.prt
	# out would be  c:/Creo/Work/ActiveSimpleDim-box.prt.csv
	#
	set out [file join [ps_pwd] ActiveSimpleDim-$model.csv]

	# open the file for write
	set fp [open  $out w]

	# prepare a header, if not skip the next 2  lines of code
	# could be done in onle line as well
	set COLS [list  FeatID DimID DimSymbol DimValue]
	puts $fp [join $COLS ,]

	# Get all active feature IDs, skip suppressed ...
	set ActiveFeats [ps_feat list -active true]

	# this will return a nested list
	# foreach ActiveFeats ID a list of dims or an empty list
	set dimObjLists  [ps_dim by_feat  -model $model -- $ActiveFeats] 

	# now check the list for each feat id
	foreach dimObjList $dimObjLists ActiveFeat $ActiveFeats {

		# if we have no dim for this feature continue
		if {[llength $dimObjList] == 0} continue

		# walk through the list of dimObj
		foreach dimObj $dimObjList {

			# get id, symbol and value
			set id 	[$dimObj cget -id]
			set sym [$dimObj cget -symbol]
			set val [$dimObj cget -value]

			# write to file
			puts $fp [join [list $ActiveFeat $id $sym $val] ,]


		}

	}

	close $fp

}
# Call with the current model
ActiveOut [ps_model cur]

 

 

 

 

 

 

Last example: Just export a specific dimension type including tolerance and some dimension tags

 

 

 

 

 

#
# export only a dimension value from type diameter
# add tolernce values and inspection basic info

# sample out (of course out is without the '#')
# Symbol,Value,TolL,TolH,Inspection,Basic
# d2,32.000,0.005334,0.005334,No,No
# d12,5.334,0.005334,0.005334,No,No
# d27,10.667,0.005334,0.005334,No,No

# if sep is not given use ','
proc SimpleByType {model { sep {,} } } {
	set B(0) No
	set B(1) Yes
	set dims [ps_dim list]

	set out [file join [ps_pwd] dim-info-by-type--$model.csv]

	set fp [open $out w]

	puts $fp "Symbol,Value,TolL,TolH,Inspection,Basic"

	foreach item $dims {

		# assign id sym val to a var from the list item
		foreach {id sym val} $item break

		# get the dim Object handle
		set dimObj [ps_dim from_ids $id]
		# Only export if we have a diameter dimension	
		if {[string equal [$dimObj cget -type ] DIAMETER ] } {

			# get the tolerance, a list of 2 double values
			set tol 	[$dimObj  cget -tolerance ]
			# assign lower, upper value
			set toll 	[lindex $tol 0 ]
			set tolu 	[lindex $tol 1 ]
			#export if inspection or basic
			set insp 	[$dimObj  cget -inspection ]
			set basic 	[$dimObj  cget -basic ]

			set data [join [list $sym [format %.3f $val] $toll $tolu $B($insp) $B($basic)] $sep]
			puts $fp $data
		}


	}

	# close the file
	close $fp

}

# just call the procedure with the current model
SimpleByType[ps_model cur]

 

 

 

 

 

 

Thats it, good luck with VB.

View solution in original post

SM_9791973
7-Bedrock
(To:RPN)

Thanks a lot for the programming.... it worked for me....

 

Announcements