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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Using VB API to select CSYS

CADCAMTECH
4-Participant

Using VB API to select CSYS

Dear 

 

Please help me example VB API in Creo

Create a button1 select CSYS in Creo then get name show in textbox1 in VB.

I want to create button in VB so select object in Creo, I had read ptc document but difficult for me to find example.

 

Thanks

5 REPLIES 5
RPN
17-Peridot
17-Peridot
(To:CADCAMTECH)

I couldn't resist, in Tcl I need this:

# Assume a 3D model is active, 
# and contains only one (to make the result clear) Csys with feature ID 11
# The Csys/Type/Geom ID off the Csys is 58
# No error checking in this code here

# Create Selection Object 'selObj' is the name of the object ps_sel selObj # Now ask the user to select a 'csys' (controls goes to Creo) selObj select csys # back from Creo, get the model item, note you selected a CSYS and not a FEATURE selObj modelitem miObj # Get the CSYS GeomID, after this command, GeomID will hold 58 set GeomID [miObj cget -id] # Get the Feature ID, after this command FeatID will hold the Value '11' set FeatID [ps_geom to_feat_ids CSYS $GeomID]

For the selection only, 2 lines of code Smiley Very Happy

 

CADCAMTECH
4-Participant
(To:RPN)

Dear Sir

 

Thanks your reply, I had follow your code but error.

I'm using Visual Basic 2016 Windows form Application not C# (I dont know)

I want to get name CSYS to textbox1

 

Thanks advance your help

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

That's simple, you have the model handel, and the feature ID, now you can get the feature name with this two references. In Tcl, working on the current model:

 

# Get the Feature Name
set FeatName [ps_feat name $FeatID]
CADCAMTECH
4-Participant
(To:RPN)

Dear Sir

 

Can you help more detail

I don't want feat ID,

I just want create a button in VB API => then select one of any Csys in Creo => then get name to textbox1 in VB API

 

Thanks

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

Hello CCT, no I will and I can't provide a VB script, because I don't use VB, it's hard to read for me and you need to write so much code. I did it with Tcl, on the fly (All options need a leading '-' 🙂   )

 

Now have fun with VB!

 

proc Init {} {
	# Destroy for ReRun, else on ReRun an error would generated
	destroy		.ptc
	ps_destroy	miObj selObj
	# Main Window
	toplevel		.ptc
	# Place it
	wm geom .ptc -400+200
	# Button and Entry with text a global variable
	pack [button .ptc.b1 -text "Select CSYS" -command SelectAndUpdate]
	pack [entry  .ptc.e1 -textvar NAME_OF_MODELITEM -width 35 ]
	# Craete modelitem and selection Object/Command, selObj will reference the miObj
	ps_modelitem 		miObj	-update yes
	ps_sel		selObj -modelitem miObj
}

proc SelectAndUpdate {} {
	# Select the Csys
	selObj sel csys
	# Get the data to the global var ::NAME_OF_MODELITEM this will update the entry value
	set ::NAME_OF_MODELITEM "Name: [miObj cget -name] ID: [miObj cget -id] Type: [miObj cget -type]"
}

Init

 

Top Tags