QUOTE
(I think I am too beginner to write the undo/redo code so I set my command to be undoable at the moment).
No, this is not a solution. If your command modifies the DG (and it does!), then you MUST implement undo/redo.
Regarding the other problem, I believe the kGeometric implies that the node is also compatible with kDagNode and therefore a dag node.
You are using iter.getDependNode(objShapeNode); to retrieve a dag node from the selection list iterator. This will not do. You must use iter.getDagPath(objShapeNode); if you want to retrieve a dag node.
See iter.itemType to check of your're dealing with a kDagSelectionItem and therefore should use getDagPath or if your'Re dealing with a kDNselectionItem and therefore should use getDependNode (since plain dependency nodes don't have a dag path). But anyway, you're filtering your selection to kDagNodes (which I _believe_ contains kGeometry as a subset) so you should not be encountering plain dependency nodes and therefore you should not need to use getDependNode at all.
Do not check for (stat != 0) to see if retrieveing the node succeeded, but use (stat == MStatus::kSuccess) instead. This is because
CODE
class OPENMAYA_EXPORT MStatus
{
public:
/// Available Status Codes
enum MStatusCode
{
/// The operation was successful
kSuccess = 0,
/// The operation failed
kFailure,
/// The operation failed due to insufficient memory
kInsufficientMemory,
/// An invalid parameter was provided
kInvalidParameter,
/// Application is not licensed for the attempted operation
kLicenseFailure,
/// Returned by MPxNode::compute for unrecognised plugs
kUnknownParameter,
/// Not currently used
kNotImplemented,
/// Not currently used
kNotFound,
/// Not currently used
kEndOfFile
};
defines that kSuccess = 0, and therefore (stat == 0) or (!stat) is succeeding. So you are checking for failure if your're checking for (stat).
So you see that actually getDependNode has been failing all the time and therefore objShapeNode and objDepNodeFn are invalid. this means that objDepNodeFn.findPlug("worldSpace[0]") will fail and thus the connection can't be made.
The only lesson you can take from this is that you should always check return values (MStatus), and check them against the enum (MStatus::kSucceeded or MStatus::kFailed).
Also, you really must implement undo/redo.